test_electriq_desd9lw_dehumidifier.py 10 KB

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