test_wetair_wch750_heater.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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")
  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.assertCountEqual(
  158. self.subject.device_state_attributes,
  159. {
  160. "timer": "1h",
  161. "countdown": 20,
  162. "unknown_21": 21,
  163. },
  164. )
  165. def test_light_color_mode(self):
  166. self.assertEqual(self.light.color_mode, COLOR_MODE_BRIGHTNESS)
  167. def test_light_icon(self):
  168. self.assertEqual(self.light.icon, None)
  169. def test_light_is_on(self):
  170. self.dps[BRIGHTNESS_DPS] = "level0"
  171. self.assertEqual(self.light.is_on, False)
  172. self.dps[BRIGHTNESS_DPS] = "level1"
  173. self.assertEqual(self.light.is_on, True)
  174. self.dps[BRIGHTNESS_DPS] = "level2"
  175. self.assertEqual(self.light.is_on, True)
  176. self.dps[BRIGHTNESS_DPS] = "level3"
  177. self.assertEqual(self.light.is_on, True)
  178. # Test the case where device is not ready does not cause errors that
  179. # would prevent initialization.
  180. self.dps[BRIGHTNESS_DPS] = None
  181. self.assertEqual(self.light.is_on, False)
  182. def test_light_brightness(self):
  183. self.dps[BRIGHTNESS_DPS] = "level0"
  184. self.assertEqual(self.light.brightness, 0)
  185. self.dps[BRIGHTNESS_DPS] = "level1"
  186. self.assertEqual(self.light.brightness, 85)
  187. self.dps[BRIGHTNESS_DPS] = "level2"
  188. self.assertEqual(self.light.brightness, 170)
  189. self.dps[BRIGHTNESS_DPS] = "level3"
  190. self.assertEqual(self.light.brightness, 255)
  191. def test_light_state_attributes(self):
  192. self.assertEqual(self.light.device_state_attributes, {})
  193. async def test_light_turn_on(self):
  194. async with assert_device_properties_set(
  195. self.light._device, {BRIGHTNESS_DPS: "level3"}
  196. ):
  197. await self.light.async_turn_on()
  198. async def test_light_turn_off(self):
  199. async with assert_device_properties_set(
  200. self.light._device,
  201. {BRIGHTNESS_DPS: "level0"},
  202. ):
  203. await self.light.async_turn_off()
  204. async def test_light_brightness_to_low(self):
  205. async with assert_device_properties_set(
  206. self.light._device,
  207. {BRIGHTNESS_DPS: "level1"},
  208. ):
  209. await self.light.async_turn_on(brightness=85)
  210. async def test_light_brightness_to_mid(self):
  211. async with assert_device_properties_set(
  212. self.light._device,
  213. {BRIGHTNESS_DPS: "level2"},
  214. ):
  215. await self.light.async_turn_on(brightness=170)
  216. async def test_light_brightness_to_high(self):
  217. async with assert_device_properties_set(
  218. self.light._device,
  219. {BRIGHTNESS_DPS: "level3"},
  220. ):
  221. await self.light.async_turn_on(brightness=255)
  222. async def test_light_brightness_to_off(self):
  223. async with assert_device_properties_set(
  224. self.light._device,
  225. {BRIGHTNESS_DPS: "level0"},
  226. ):
  227. await self.light.async_turn_on(brightness=0)
  228. async def test_toggle_turns_the_light_on_when_it_was_off(self):
  229. self.dps[BRIGHTNESS_DPS] = "level0"
  230. async with assert_device_properties_set(
  231. self.light._device,
  232. {BRIGHTNESS_DPS: "level3"},
  233. ):
  234. await self.light.async_toggle()
  235. async def test_toggle_turns_the_light_off_when_it_was_on(self):
  236. self.dps[BRIGHTNESS_DPS] = "level2"
  237. async with assert_device_properties_set(
  238. self.light._device,
  239. {BRIGHTNESS_DPS: "level0"},
  240. ):
  241. await self.light.async_toggle()
  242. async def test_light_brightness_snaps(self):
  243. async with assert_device_properties_set(
  244. self.light._device,
  245. {BRIGHTNESS_DPS: "level1"},
  246. ):
  247. await self.light.async_turn_on(brightness=100)