test_electriq_desd9lw_dehumidifier.py 11 KB

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