test_wetair_wch750_heater.py 12 KB

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