test_electriq_desd9lw_dehumidifier.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_AUTO,
  3. HVAC_MODE_DRY,
  4. HVAC_MODE_FAN_ONLY,
  5. HVAC_MODE_HEAT,
  6. HVAC_MODE_OFF,
  7. SUPPORT_FAN_MODE,
  8. SUPPORT_SWING_MODE,
  9. SUPPORT_TARGET_HUMIDITY,
  10. SUPPORT_TARGET_TEMPERATURE,
  11. )
  12. from homeassistant.const import STATE_UNAVAILABLE
  13. from ..const import ELECTRIQ_DESD9LW_DEHUMIDIFIER_PAYLOAD
  14. from ..helpers import assert_device_properties_set
  15. from .base_device_tests import TuyaDeviceTestCase
  16. POWER_DPS = "1"
  17. HUMIDITY_DPS = "2"
  18. FAN_DPS = "4"
  19. HVACMODE_DPS = "5"
  20. CURRENTHUM_DPS = "6"
  21. CURRENTTEMP_DPS = "7"
  22. SWING_DPS = "10"
  23. SWITCH_DPS = "12"
  24. LIGHT_DPS = "15"
  25. TEMPERATURE_DPS = "101"
  26. class TestElectriqDESD9LWDehumidifier(TuyaDeviceTestCase):
  27. __test__ = True
  28. def setUp(self):
  29. self.setUpForConfig(
  30. "electriq_desd9lw_dehumidifier.yaml",
  31. ELECTRIQ_DESD9LW_DEHUMIDIFIER_PAYLOAD,
  32. )
  33. self.subject = self.entities.get("climate")
  34. self.light = self.entities.get("light")
  35. self.switch = self.entities.get("switch")
  36. def test_supported_features(self):
  37. self.assertEqual(
  38. self.subject.supported_features,
  39. SUPPORT_FAN_MODE
  40. | SUPPORT_SWING_MODE
  41. | SUPPORT_TARGET_HUMIDITY
  42. | SUPPORT_TARGET_TEMPERATURE,
  43. )
  44. def test_icon(self):
  45. self.dps[POWER_DPS] = True
  46. self.dps[HVACMODE_DPS] = "Auto"
  47. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  48. self.dps[HVACMODE_DPS] = "Dehumidity"
  49. self.assertEqual(self.subject.icon, "mdi:water")
  50. self.dps[HVACMODE_DPS] = "Heater"
  51. self.assertEqual(self.subject.icon, "mdi:fire")
  52. self.dps[HVACMODE_DPS] = "Fan"
  53. self.assertEqual(self.subject.icon, "mdi:fan")
  54. self.dps[POWER_DPS] = False
  55. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  56. def test_temperature_unit_returns_device_temperature_unit(self):
  57. self.assertEqual(
  58. self.subject.temperature_unit, self.subject._device.temperature_unit
  59. )
  60. def test_target_temperature(self):
  61. self.dps[TEMPERATURE_DPS] = 24
  62. self.assertEqual(self.subject.target_temperature, 24)
  63. def test_target_temperature_step(self):
  64. self.assertEqual(self.subject.target_temperature_step, 1)
  65. def test_minimum_target_temperature(self):
  66. self.assertEqual(self.subject.min_temp, 16)
  67. def test_maximum_target_temperature(self):
  68. self.assertEqual(self.subject.max_temp, 30)
  69. async def test_legacy_set_temperature_with_temperature(self):
  70. async with assert_device_properties_set(
  71. self.subject._device, {TEMPERATURE_DPS: 22}
  72. ):
  73. await self.subject.async_set_temperature(temperature=22)
  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_rounds_value_to_closest_integer(self):
  78. async with assert_device_properties_set(
  79. self.subject._device, {TEMPERATURE_DPS: 23}
  80. ):
  81. await self.subject.async_set_target_temperature(22.6)
  82. async def test_set_target_temperature_fails_outside_valid_range(self):
  83. with self.assertRaisesRegex(
  84. ValueError, "temperature \\(15\\) must be between 16 and 30"
  85. ):
  86. await self.subject.async_set_target_temperature(15)
  87. with self.assertRaisesRegex(
  88. ValueError, "temperature \\(31\\) must be between 16 and 30"
  89. ):
  90. await self.subject.async_set_target_temperature(31)
  91. def test_current_temperature(self):
  92. self.dps[CURRENTTEMP_DPS] = 21
  93. self.assertEqual(self.subject.current_temperature, 21)
  94. def test_current_humidity(self):
  95. self.dps[CURRENTHUM_DPS] = 60
  96. self.assertEqual(self.subject.current_humidity, 60)
  97. def test_min_target_humidity(self):
  98. self.assertEqual(self.subject.min_humidity, 35)
  99. def test_max_target_humidity(self):
  100. self.assertEqual(self.subject.max_humidity, 80)
  101. def test_target_humidity(self):
  102. self.dps[HUMIDITY_DPS] = 45
  103. self.assertEqual(self.subject.target_humidity, 45)
  104. async def test_set_target_humidity_rounds_to_5_percent(self):
  105. async with assert_device_properties_set(
  106. self.subject._device,
  107. {HUMIDITY_DPS: 55},
  108. ):
  109. await self.subject.async_set_humidity(53)
  110. async with assert_device_properties_set(
  111. self.subject._device,
  112. {HUMIDITY_DPS: 45},
  113. ):
  114. await self.subject.async_set_humidity(47)
  115. def test_hvac_mode(self):
  116. self.dps[POWER_DPS] = True
  117. self.dps[HVACMODE_DPS] = "Heater"
  118. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  119. self.dps[HVACMODE_DPS] = "Dehumidity"
  120. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
  121. self.dps[HVACMODE_DPS] = "Fan"
  122. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  123. self.dps[HVACMODE_DPS] = "Auto"
  124. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  125. self.dps[HVACMODE_DPS] = None
  126. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  127. self.dps[HVACMODE_DPS] = "Auto"
  128. self.dps[POWER_DPS] = False
  129. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  130. def test_hvac_modes(self):
  131. self.assertCountEqual(
  132. self.subject.hvac_modes,
  133. [
  134. HVAC_MODE_AUTO,
  135. HVAC_MODE_DRY,
  136. HVAC_MODE_FAN_ONLY,
  137. HVAC_MODE_HEAT,
  138. HVAC_MODE_OFF,
  139. ],
  140. )
  141. async def test_turn_on(self):
  142. self.dps[HVACMODE_DPS] = "Auto"
  143. self.dps[POWER_DPS] = False
  144. async with assert_device_properties_set(
  145. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "Heater"}
  146. ):
  147. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  148. async def test_turn_off(self):
  149. self.dps[HVACMODE_DPS] = "Auto"
  150. self.dps[POWER_DPS] = True
  151. async with assert_device_properties_set(
  152. self.subject._device, {POWER_DPS: False}
  153. ):
  154. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  155. async def test_set_mode_to_heater(self):
  156. self.dps[HVACMODE_DPS] = "Auto"
  157. self.dps[POWER_DPS] = True
  158. async with assert_device_properties_set(
  159. self.subject._device, {HVACMODE_DPS: "Heater", POWER_DPS: True}
  160. ):
  161. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  162. async def test_set_mode_to_dehumidity(self):
  163. self.dps[HVACMODE_DPS] = "Auto"
  164. self.dps[POWER_DPS] = True
  165. async with assert_device_properties_set(
  166. self.subject._device, {HVACMODE_DPS: "Dehumidity", POWER_DPS: True}
  167. ):
  168. await self.subject.async_set_hvac_mode(HVAC_MODE_DRY)
  169. async def test_set_mode_to_fan(self):
  170. self.dps[HVACMODE_DPS] = "Auto"
  171. self.dps[POWER_DPS] = True
  172. async with assert_device_properties_set(
  173. self.subject._device, {HVACMODE_DPS: "Fan", POWER_DPS: True}
  174. ):
  175. await self.subject.async_set_hvac_mode(HVAC_MODE_FAN_ONLY)
  176. async def test_set_mode_to_auto(self):
  177. self.dps[HVACMODE_DPS] = "Fan"
  178. self.dps[POWER_DPS] = True
  179. async with assert_device_properties_set(
  180. self.subject._device, {HVACMODE_DPS: "Auto", POWER_DPS: True}
  181. ):
  182. await self.subject.async_set_hvac_mode(HVAC_MODE_AUTO)
  183. def test_fan_mode(self):
  184. self.dps[FAN_DPS] = "Low"
  185. self.assertEqual(self.subject.fan_mode, "Low")
  186. self.dps[FAN_DPS] = "Medium"
  187. self.assertEqual(self.subject.fan_mode, "Medium")
  188. self.dps[FAN_DPS] = "High"
  189. self.assertEqual(self.subject.fan_mode, "High")
  190. def test_fan_mode_invalid_in_auto_hvac_mode(self):
  191. self.dps[HVACMODE_DPS] = "Auto"
  192. self.dps[FAN_DPS] = "Low"
  193. self.assertIs(self.subject.fan_mode, None)
  194. def test_fan_modes(self):
  195. self.assertCountEqual(
  196. self.subject.fan_modes,
  197. ["Low", "Medium", "High"],
  198. )
  199. async def test_set_fan_mode_to_low(self):
  200. async with assert_device_properties_set(self.subject._device, {FAN_DPS: "Low"}):
  201. await self.subject.async_set_fan_mode("Low")
  202. async def test_set_fan_mode_to_medium(self):
  203. async with assert_device_properties_set(
  204. self.subject._device, {FAN_DPS: "Medium"}
  205. ):
  206. await self.subject.async_set_fan_mode("Medium")
  207. async def test_set_fan_mode_to_high(self):
  208. async with assert_device_properties_set(
  209. self.subject._device, {FAN_DPS: "High"}
  210. ):
  211. await self.subject.async_set_fan_mode("High")
  212. def test_swing_modes(self):
  213. self.assertCountEqual(
  214. self.subject.swing_modes,
  215. ["off", "vertical"],
  216. )
  217. def test_swing_mode(self):
  218. self.dps[SWING_DPS] = False
  219. self.assertEqual(self.subject.swing_mode, "off")
  220. self.dps[SWING_DPS] = True
  221. self.assertEqual(self.subject.swing_mode, "vertical")
  222. async def test_set_swing_mode_to_vertical(self):
  223. async with assert_device_properties_set(
  224. self.subject._device,
  225. {SWING_DPS: True},
  226. ):
  227. await self.subject.async_set_swing_mode("vertical")
  228. async def test_set_swing_mode_to_off(self):
  229. async with assert_device_properties_set(
  230. self.subject._device,
  231. {SWING_DPS: False},
  232. ):
  233. await self.subject.async_set_swing_mode("off")
  234. def test_light_state_attributes(self):
  235. self.assertEqual(self.light.device_state_attributes, {})
  236. def test_light_is_on(self):
  237. self.dps[LIGHT_DPS] = True
  238. self.assertTrue(self.light.is_on)
  239. self.dps[LIGHT_DPS] = False
  240. self.assertFalse(self.light.is_on)
  241. async def test_light_turn_on(self):
  242. async with assert_device_properties_set(
  243. self.light._device,
  244. {LIGHT_DPS: True},
  245. ):
  246. await self.light.async_turn_on()
  247. async def test_light_turn_off(self):
  248. async with assert_device_properties_set(
  249. self.light._device,
  250. {LIGHT_DPS: False},
  251. ):
  252. await self.light.async_turn_off()
  253. async def test_toggle_turns_the_light_on_when_it_was_off(self):
  254. self.dps[LIGHT_DPS] = False
  255. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: True}):
  256. await self.light.async_toggle()
  257. async def test_toggle_turns_the_light_off_when_it_was_on(self):
  258. self.dps[LIGHT_DPS] = True
  259. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: False}):
  260. await self.light.async_toggle()
  261. def test_light_icon(self):
  262. self.assertEqual(self.light.icon, "mdi:solar-power")
  263. def test_switch_state_attributes(self):
  264. self.assertEqual(self.switch.device_state_attributes, {})
  265. def test_switch_is_on(self):
  266. self.dps[SWITCH_DPS] = True
  267. self.assertTrue(self.switch.is_on)
  268. self.dps[SWITCH_DPS] = False
  269. self.assertFalse(self.switch.is_on)
  270. async def test_switch_turn_on(self):
  271. async with assert_device_properties_set(
  272. self.switch._device,
  273. {SWITCH_DPS: True},
  274. ):
  275. await self.switch.async_turn_on()
  276. async def test_switch_turn_off(self):
  277. async with assert_device_properties_set(
  278. self.switch._device,
  279. {SWITCH_DPS: False},
  280. ):
  281. await self.switch.async_turn_off()
  282. async def test_toggle_turns_the_switch_on_when_it_was_off(self):
  283. self.dps[SWITCH_DPS] = False
  284. async with assert_device_properties_set(
  285. self.switch._device, {SWITCH_DPS: True}
  286. ):
  287. await self.switch.async_toggle()
  288. async def test_toggle_turns_the_switch_off_when_it_was_on(self):
  289. self.dps[SWITCH_DPS] = True
  290. async with assert_device_properties_set(
  291. self.switch._device, {SWITCH_DPS: False}
  292. ):
  293. await self.switch.async_toggle()
  294. def test_switch_icon(self):
  295. self.assertEqual(self.switch.icon, "mdi:atom-variant")