test_purline_m100_heater.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_FAN_ONLY,
  3. HVAC_MODE_HEAT,
  4. HVAC_MODE_OFF,
  5. SUPPORT_PRESET_MODE,
  6. SUPPORT_SWING_MODE,
  7. SUPPORT_TARGET_TEMPERATURE,
  8. SWING_OFF,
  9. SWING_VERTICAL,
  10. )
  11. from homeassistant.components.light import COLOR_MODE_ONOFF
  12. from homeassistant.components.switch import DEVICE_CLASS_SWITCH
  13. from homeassistant.const import STATE_UNAVAILABLE
  14. from ..const import PURLINE_M100_HEATER_PAYLOAD
  15. from ..helpers import (
  16. assert_device_properties_set,
  17. assert_device_properties_set_optional,
  18. )
  19. from .base_device_tests import BasicSwitchTests, TuyaDeviceTestCase
  20. HVACMODE_DPS = "1"
  21. TEMPERATURE_DPS = "2"
  22. CURRENTTEMP_DPS = "3"
  23. PRESET_DPS = "5"
  24. LIGHTOFF_DPS = "10"
  25. TIMERHR_DPS = "11"
  26. TIMER_DPS = "12"
  27. SWITCH_DPS = "101"
  28. SWING_DPS = "102"
  29. class TestPulineM100Heater(BasicSwitchTests, TuyaDeviceTestCase):
  30. __test__ = True
  31. def setUp(self):
  32. self.setUpForConfig("purline_m100_heater.yaml", PURLINE_M100_HEATER_PAYLOAD)
  33. self.subject = self.entities.get("climate")
  34. # BasicLightTests mixin not used due to inverted switch
  35. self.light = self.entities.get("light_display")
  36. self.setUpBasicSwitch(
  37. SWITCH_DPS, self.entities.get("switch_open_window_detector")
  38. )
  39. def test_supported_features(self):
  40. self.assertEqual(
  41. self.subject.supported_features,
  42. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE | SUPPORT_SWING_MODE,
  43. )
  44. def test_icon(self):
  45. self.dps[HVACMODE_DPS] = True
  46. self.dps[PRESET_DPS] = "auto"
  47. self.assertEqual(self.subject.icon, "mdi:radiator")
  48. self.dps[HVACMODE_DPS] = False
  49. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  50. self.dps[HVACMODE_DPS] = True
  51. self.dps[PRESET_DPS] = "off"
  52. self.assertEqual(self.subject.icon, "mdi:fan")
  53. def test_temperature_unit_returns_device_temperature_unit(self):
  54. self.assertEqual(
  55. self.subject.temperature_unit, self.subject._device.temperature_unit
  56. )
  57. def test_target_temperature(self):
  58. self.dps[TEMPERATURE_DPS] = 25
  59. self.assertEqual(self.subject.target_temperature, 25)
  60. def test_target_temperature_step(self):
  61. self.assertEqual(self.subject.target_temperature_step, 1)
  62. def test_minimum_target_temperature(self):
  63. self.assertEqual(self.subject.min_temp, 15)
  64. def test_maximum_target_temperature(self):
  65. self.assertEqual(self.subject.max_temp, 35)
  66. async def test_legacy_set_temperature_with_temperature(self):
  67. async with assert_device_properties_set(
  68. self.subject._device, {TEMPERATURE_DPS: 25}
  69. ):
  70. await self.subject.async_set_temperature(temperature=25)
  71. async def test_legacy_set_temperature_with_no_valid_properties(self):
  72. await self.subject.async_set_temperature(something="else")
  73. self.subject._device.async_set_property.assert_not_called()
  74. async def test_set_target_temperature(self):
  75. async with assert_device_properties_set(
  76. self.subject._device, {TEMPERATURE_DPS: 25}
  77. ):
  78. await self.subject.async_set_target_temperature(25)
  79. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  80. async with assert_device_properties_set(
  81. self.subject._device,
  82. {TEMPERATURE_DPS: 25},
  83. ):
  84. await self.subject.async_set_target_temperature(24.6)
  85. async def test_set_target_temperature_fails_outside_valid_range(self):
  86. with self.assertRaisesRegex(
  87. ValueError, "temperature \\(4\\) must be between 15 and 35"
  88. ):
  89. await self.subject.async_set_target_temperature(4)
  90. with self.assertRaisesRegex(
  91. ValueError, "temperature \\(36\\) must be between 15 and 35"
  92. ):
  93. await self.subject.async_set_target_temperature(36)
  94. def test_current_temperature(self):
  95. self.dps[CURRENTTEMP_DPS] = 25
  96. self.assertEqual(self.subject.current_temperature, 25)
  97. def test_hvac_mode(self):
  98. self.dps[HVACMODE_DPS] = True
  99. self.dps[PRESET_DPS] = "auto"
  100. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  101. self.dps[PRESET_DPS] = "off"
  102. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  103. self.dps[HVACMODE_DPS] = False
  104. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  105. self.dps[HVACMODE_DPS] = None
  106. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  107. def test_hvac_modes(self):
  108. self.assertCountEqual(
  109. self.subject.hvac_modes,
  110. [HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_FAN_ONLY],
  111. )
  112. async def test_turn_on(self):
  113. async with assert_device_properties_set_optional(
  114. self.subject._device,
  115. {HVACMODE_DPS: True},
  116. {PRESET_DPS: "auto"},
  117. ):
  118. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  119. async def test_turn_off(self):
  120. async with assert_device_properties_set(
  121. self.subject._device,
  122. {HVACMODE_DPS: False},
  123. ):
  124. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  125. async def test_turn_on_fan(self):
  126. async with assert_device_properties_set_optional(
  127. self.subject._device,
  128. {HVACMODE_DPS: True},
  129. {PRESET_DPS: "off"},
  130. ):
  131. await self.subject.async_set_hvac_mode(HVAC_MODE_FAN_ONLY)
  132. def test_preset_mode(self):
  133. self.dps[PRESET_DPS] = "auto"
  134. self.assertEqual(self.subject.preset_mode, "Auto")
  135. self.dps[PRESET_DPS] = "off"
  136. self.assertEqual(self.subject.preset_mode, "Fan")
  137. self.dps[PRESET_DPS] = "4"
  138. self.assertEqual(self.subject.preset_mode, "4")
  139. self.dps[PRESET_DPS] = None
  140. self.assertIs(self.subject.preset_mode, None)
  141. def test_preset_modes(self):
  142. self.assertCountEqual(
  143. self.subject.preset_modes,
  144. ["Fan", "1", "2", "3", "4", "5", "Auto"],
  145. )
  146. async def test_set_preset_mode_numeric(self):
  147. async with assert_device_properties_set(
  148. self.subject._device,
  149. {PRESET_DPS: "3"},
  150. ):
  151. await self.subject.async_set_preset_mode("3")
  152. def test_swing_mode(self):
  153. self.dps[SWING_DPS] = True
  154. self.assertEqual(self.subject.swing_mode, SWING_VERTICAL)
  155. self.dps[SWING_DPS] = False
  156. self.assertEqual(self.subject.swing_mode, SWING_OFF)
  157. def test_swing_modes(self):
  158. self.assertCountEqual(
  159. self.subject.swing_modes,
  160. [SWING_OFF, SWING_VERTICAL],
  161. )
  162. async def test_set_swing_mode_on(self):
  163. async with assert_device_properties_set(
  164. self.subject._device, {SWING_DPS: True}
  165. ):
  166. await self.subject.async_set_swing_mode(SWING_VERTICAL)
  167. async def test_set_swing_mode_off(self):
  168. async with assert_device_properties_set(
  169. self.subject._device, {SWING_DPS: False}
  170. ):
  171. await self.subject.async_set_swing_mode(SWING_OFF)
  172. def test_light_supported_color_modes(self):
  173. self.assertCountEqual(
  174. self.light.supported_color_modes,
  175. [COLOR_MODE_ONOFF],
  176. )
  177. def test_light_color_mode(self):
  178. self.assertEqual(self.light.color_mode, COLOR_MODE_ONOFF)
  179. def test_light_icon(self):
  180. self.dps[LIGHTOFF_DPS] = False
  181. self.assertEqual(self.light.icon, "mdi:led-on")
  182. self.dps[LIGHTOFF_DPS] = True
  183. self.assertEqual(self.light.icon, "mdi:led-off")
  184. def test_light_is_on(self):
  185. self.dps[LIGHTOFF_DPS] = False
  186. self.assertTrue(self.light.is_on)
  187. self.dps[LIGHTOFF_DPS] = True
  188. self.assertFalse(self.light.is_on)
  189. def test_light_state_attributes(self):
  190. self.assertEqual(self.light.device_state_attributes, {})
  191. async def test_light_turn_on(self):
  192. async with assert_device_properties_set(
  193. self.light._device, {LIGHTOFF_DPS: False}
  194. ):
  195. await self.light.async_turn_on()
  196. async def test_light_turn_off(self):
  197. async with assert_device_properties_set(
  198. self.light._device, {LIGHTOFF_DPS: True}
  199. ):
  200. await self.light.async_turn_off()
  201. async def test_toggle_turns_the_light_on_when_it_was_off(self):
  202. self.dps[LIGHTOFF_DPS] = True
  203. async with assert_device_properties_set(
  204. self.light._device, {LIGHTOFF_DPS: False}
  205. ):
  206. await self.light.async_toggle()
  207. async def test_toggle_turns_the_light_off_when_it_was_on(self):
  208. self.dps[LIGHTOFF_DPS] = False
  209. async with assert_device_properties_set(
  210. self.light._device, {LIGHTOFF_DPS: True}
  211. ):
  212. await self.light.async_toggle()