test_electriq_desd9lw_dehumidifier.py 9.3 KB

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