test_wetair_wch750_heater.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_HEAT,
  3. HVAC_MODE_OFF,
  4. PRESET_AWAY,
  5. PRESET_COMFORT,
  6. PRESET_BOOST,
  7. SUPPORT_PRESET_MODE,
  8. SUPPORT_TARGET_TEMPERATURE,
  9. )
  10. from homeassistant.components.light import COLOR_MODE_BRIGHTNESS
  11. from homeassistant.const import STATE_UNAVAILABLE
  12. from ..const import WETAIR_WCH750_HEATER_PAYLOAD
  13. from ..helpers import assert_device_properties_set
  14. from .base_device_tests import TuyaDeviceTestCase
  15. HVACMODE_DPS = "1"
  16. TEMPERATURE_DPS = "2"
  17. PRESET_DPS = "4"
  18. HVACACTION_DPS = "11"
  19. TIMER_DPS = "19"
  20. COUNTDOWN_DPS = "20"
  21. UNKNOWN21_DPS = "21"
  22. BRIGHTNESS_DPS = "101"
  23. class TestWetairWCH750Heater(TuyaDeviceTestCase):
  24. __test__ = True
  25. def setUp(self):
  26. self.setUpForConfig("wetair_wch750_heater.yaml", WETAIR_WCH750_HEATER_PAYLOAD)
  27. self.subject = self.entities.get("climate")
  28. self.light = self.entities.get("light_display")
  29. def test_supported_features(self):
  30. self.assertEqual(
  31. self.subject.supported_features,
  32. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  33. )
  34. def test_icon(self):
  35. self.dps[HVACMODE_DPS] = True
  36. self.assertEqual(self.subject.icon, "mdi:radiator")
  37. self.dps[HVACMODE_DPS] = False
  38. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  39. def test_temperatre_unit_retrns_device_temperatre_unit(self):
  40. self.assertEqual(
  41. self.subject.temperature_unit, self.subject._device.temperature_unit
  42. )
  43. def test_target_temperature(self):
  44. self.dps[TEMPERATURE_DPS] = 25
  45. self.assertEqual(self.subject.target_temperature, 25)
  46. def test_target_temperature_in_af_mode(self):
  47. self.dps[TEMPERATURE_DPS] = 25
  48. self.dps[PRESET_DPS] = "mod_antiforst"
  49. self.assertEqual(self.subject.target_temperature, None)
  50. def test_target_temperature_step(self):
  51. self.assertEqual(self.subject.target_temperature_step, 1)
  52. def test_minimum_temperature(self):
  53. self.assertEqual(self.subject.min_temp, 10)
  54. def test_maximum_temperature(self):
  55. self.assertEqual(self.subject.max_temp, 35)
  56. async def test_legacy_set_temperature_with_temperature(self):
  57. async with assert_device_properties_set(
  58. self.subject._device, {TEMPERATURE_DPS: 25}
  59. ):
  60. await self.subject.async_set_temperature(temperature=25)
  61. async def test_legacy_set_temperature_with_preset_mode(self):
  62. async with assert_device_properties_set(
  63. self.subject._device, {PRESET_DPS: "mod_antiforst"}
  64. ):
  65. await self.subject.async_set_temperature(preset_mode=PRESET_AWAY)
  66. async def test_legacy_set_temperature_with_both_properties(self):
  67. async with assert_device_properties_set(
  68. self.subject._device,
  69. {TEMPERATURE_DPS: 25, PRESET_DPS: "mod_max12h"},
  70. ):
  71. await self.subject.async_set_temperature(
  72. preset_mode=PRESET_BOOST, temperature=25
  73. )
  74. async def test_legacy_set_temperature_with_no_valid_properties(self):
  75. await self.subject.async_set_temperature(something="else")
  76. self.subject._device.async_set_property.assert_not_called()
  77. async def test_set_target_temperature(self):
  78. async with assert_device_properties_set(
  79. self.subject._device, {TEMPERATURE_DPS: 25}
  80. ):
  81. await self.subject.async_set_target_temperature(25)
  82. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  83. async with assert_device_properties_set(
  84. self.subject._device,
  85. {TEMPERATURE_DPS: 25},
  86. ):
  87. await self.subject.async_set_target_temperature(24.6)
  88. async def test_set_target_temperature_fails_outside_valid_range(self):
  89. with self.assertRaisesRegex(
  90. ValueError, "temperature \\(9\\) must be between 10 and 35"
  91. ):
  92. await self.subject.async_set_target_temperature(9)
  93. with self.assertRaisesRegex(
  94. ValueError, "temperature \\(36\\) must be between 10 and 35"
  95. ):
  96. await self.subject.async_set_target_temperature(36)
  97. async def test_set_target_temperature_fails_in_anti_frost(self):
  98. self.dps[PRESET_DPS] = "mod_antiforst"
  99. with self.assertRaisesRegex(
  100. AttributeError, "temperature cannot be set at this time"
  101. ):
  102. await self.subject.async_set_target_temperature(25)
  103. def test_current_temperature_not_supported(self):
  104. self.assertIsNone(self.subject.current_temperature)
  105. def test_hvac_mode(self):
  106. self.dps[HVACMODE_DPS] = True
  107. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  108. self.dps[HVACMODE_DPS] = False
  109. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  110. self.dps[HVACMODE_DPS] = None
  111. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  112. def test_hvac_modes(self):
  113. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  114. async def test_turn_on(self):
  115. async with assert_device_properties_set(
  116. self.subject._device,
  117. {HVACMODE_DPS: True},
  118. ):
  119. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  120. async def test_trn_off(self):
  121. async with assert_device_properties_set(
  122. self.subject._device,
  123. {HVACMODE_DPS: False},
  124. ):
  125. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  126. def test_preset_mode(self):
  127. self.dps[PRESET_DPS] = "mod_free"
  128. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  129. self.dps[PRESET_DPS] = "mod_max12h"
  130. self.assertEqual(self.subject.preset_mode, PRESET_BOOST)
  131. self.dps[PRESET_DPS] = "mod_antiforst"
  132. self.assertEqual(self.subject.preset_mode, PRESET_AWAY)
  133. def test_preset_modes(self):
  134. self.assertCountEqual(self.subject.preset_modes, ["comfort", "boost", "away"])
  135. async def test_set_preset_mode_to_comfort(self):
  136. async with assert_device_properties_set(
  137. self.subject._device,
  138. {PRESET_DPS: "mod_free"},
  139. ):
  140. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  141. async def test_set_preset_mode_to_boost(self):
  142. async with assert_device_properties_set(
  143. self.subject._device,
  144. {PRESET_DPS: "mod_max12h"},
  145. ):
  146. await self.subject.async_set_preset_mode(PRESET_BOOST)
  147. async def test_set_preset_mode_to_away(self):
  148. async with assert_device_properties_set(
  149. self.subject._device,
  150. {PRESET_DPS: "mod_antiforst"},
  151. ):
  152. await self.subject.async_set_preset_mode(PRESET_AWAY)
  153. def test_device_state_attributes(self):
  154. self.dps[TIMER_DPS] = "1h"
  155. self.dps[COUNTDOWN_DPS] = 20
  156. self.dps[UNKNOWN21_DPS] = 21
  157. self.assertDictEqual(
  158. self.subject.device_state_attributes,
  159. {
  160. "timer": "1h",
  161. "countdown": 20,
  162. "unknown_21": 21,
  163. },
  164. )
  165. def test_light_supported_color_modes(self):
  166. self.assertCountEqual(
  167. self.light.supported_color_modes,
  168. [COLOR_MODE_BRIGHTNESS],
  169. )
  170. def test_light_color_mode(self):
  171. self.assertEqual(self.light.color_mode, COLOR_MODE_BRIGHTNESS)
  172. def test_light_icon(self):
  173. self.assertEqual(self.light.icon, None)
  174. def test_light_is_on(self):
  175. self.dps[BRIGHTNESS_DPS] = "level0"
  176. self.assertEqual(self.light.is_on, False)
  177. self.dps[BRIGHTNESS_DPS] = "level1"
  178. self.assertEqual(self.light.is_on, True)
  179. self.dps[BRIGHTNESS_DPS] = "level2"
  180. self.assertEqual(self.light.is_on, True)
  181. self.dps[BRIGHTNESS_DPS] = "level3"
  182. self.assertEqual(self.light.is_on, True)
  183. # Test the case where device is not ready does not cause errors that
  184. # would prevent initialization.
  185. self.dps[BRIGHTNESS_DPS] = None
  186. self.assertEqual(self.light.is_on, False)
  187. def test_light_brightness(self):
  188. self.dps[BRIGHTNESS_DPS] = "level0"
  189. self.assertEqual(self.light.brightness, 0)
  190. self.dps[BRIGHTNESS_DPS] = "level1"
  191. self.assertEqual(self.light.brightness, 85)
  192. self.dps[BRIGHTNESS_DPS] = "level2"
  193. self.assertEqual(self.light.brightness, 170)
  194. self.dps[BRIGHTNESS_DPS] = "level3"
  195. self.assertEqual(self.light.brightness, 255)
  196. def test_light_state_attributes(self):
  197. self.assertEqual(self.light.device_state_attributes, {})
  198. async def test_light_turn_on(self):
  199. async with assert_device_properties_set(
  200. self.light._device, {BRIGHTNESS_DPS: "level3"}
  201. ):
  202. await self.light.async_turn_on()
  203. async def test_light_turn_off(self):
  204. async with assert_device_properties_set(
  205. self.light._device,
  206. {BRIGHTNESS_DPS: "level0"},
  207. ):
  208. await self.light.async_turn_off()
  209. async def test_light_brightness_to_low(self):
  210. async with assert_device_properties_set(
  211. self.light._device,
  212. {BRIGHTNESS_DPS: "level1"},
  213. ):
  214. await self.light.async_turn_on(brightness=85)
  215. async def test_light_brightness_to_mid(self):
  216. async with assert_device_properties_set(
  217. self.light._device,
  218. {BRIGHTNESS_DPS: "level2"},
  219. ):
  220. await self.light.async_turn_on(brightness=170)
  221. async def test_light_brightness_to_high(self):
  222. async with assert_device_properties_set(
  223. self.light._device,
  224. {BRIGHTNESS_DPS: "level3"},
  225. ):
  226. await self.light.async_turn_on(brightness=255)
  227. async def test_light_brightness_to_off(self):
  228. async with assert_device_properties_set(
  229. self.light._device,
  230. {BRIGHTNESS_DPS: "level0"},
  231. ):
  232. await self.light.async_turn_on(brightness=0)
  233. async def test_toggle_turns_the_light_on_when_it_was_off(self):
  234. self.dps[BRIGHTNESS_DPS] = "level0"
  235. async with assert_device_properties_set(
  236. self.light._device,
  237. {BRIGHTNESS_DPS: "level3"},
  238. ):
  239. await self.light.async_toggle()
  240. async def test_toggle_turns_the_light_off_when_it_was_on(self):
  241. self.dps[BRIGHTNESS_DPS] = "level2"
  242. async with assert_device_properties_set(
  243. self.light._device,
  244. {BRIGHTNESS_DPS: "level0"},
  245. ):
  246. await self.light.async_toggle()
  247. async def test_light_brightness_snaps(self):
  248. async with assert_device_properties_set(
  249. self.light._device,
  250. {BRIGHTNESS_DPS: "level1"},
  251. ):
  252. await self.light.async_turn_on(brightness=100)