test_electriq_desd9lw_dehumidifier.py 8.9 KB

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