test_electriq_desd9lw_dehumidifier.py 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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
  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_device_temperature_unit(self):
  76. self.assertEqual(
  77. self.subject.temperature_unit, self.subject._device.temperature_unit
  78. )
  79. def test_current_temperature(self):
  80. self.dps[CURRENTTEMP_DPS] = 21
  81. self.assertEqual(self.subject.current_temperature, 21)
  82. def test_current_humidity(self):
  83. self.dps[CURRENTHUM_DPS] = 60
  84. self.assertEqual(self.subject.current_humidity, 60)
  85. def test_min_target_humidity(self):
  86. self.assertEqual(self.subject.min_humidity, 35)
  87. def test_max_target_humidity(self):
  88. self.assertEqual(self.subject.max_humidity, 80)
  89. def test_target_humidity(self):
  90. self.dps[HUMIDITY_DPS] = 45
  91. self.assertEqual(self.subject.target_humidity, 45)
  92. async def test_set_target_humidity_rounds_to_5_percent(self):
  93. async with assert_device_properties_set(
  94. self.subject._device,
  95. {HUMIDITY_DPS: 55},
  96. ):
  97. await self.subject.async_set_humidity(53)
  98. async with assert_device_properties_set(
  99. self.subject._device,
  100. {HUMIDITY_DPS: 45},
  101. ):
  102. await self.subject.async_set_humidity(47)
  103. def test_hvac_mode(self):
  104. self.dps[POWER_DPS] = True
  105. self.dps[HVACMODE_DPS] = "Heater"
  106. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  107. self.dps[HVACMODE_DPS] = "Dehumidity"
  108. self.assertEqual(self.subject.hvac_mode, HVACMode.DRY)
  109. self.dps[HVACMODE_DPS] = "Fan"
  110. self.assertEqual(self.subject.hvac_mode, HVACMode.FAN_ONLY)
  111. self.dps[HVACMODE_DPS] = "Auto"
  112. self.assertEqual(self.subject.hvac_mode, HVACMode.AUTO)
  113. self.dps[POWER_DPS] = False
  114. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  115. def test_hvac_modes(self):
  116. self.assertCountEqual(
  117. self.subject.hvac_modes,
  118. [
  119. HVACMode.AUTO,
  120. HVACMode.DRY,
  121. HVACMode.FAN_ONLY,
  122. HVACMode.HEAT,
  123. HVACMode.OFF,
  124. ],
  125. )
  126. async def test_turn_on(self):
  127. self.dps[HVACMODE_DPS] = "Auto"
  128. self.dps[POWER_DPS] = False
  129. async with assert_device_properties_set(
  130. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "Heater"}
  131. ):
  132. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  133. async def test_turn_off(self):
  134. self.dps[HVACMODE_DPS] = "Auto"
  135. self.dps[POWER_DPS] = True
  136. async with assert_device_properties_set(
  137. self.subject._device, {POWER_DPS: False}
  138. ):
  139. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  140. async def test_set_mode_to_heater(self):
  141. self.dps[HVACMODE_DPS] = "Auto"
  142. self.dps[POWER_DPS] = True
  143. async with assert_device_properties_set(
  144. self.subject._device, {HVACMODE_DPS: "Heater", POWER_DPS: True}
  145. ):
  146. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  147. async def test_set_mode_to_dehumidity(self):
  148. self.dps[HVACMODE_DPS] = "Auto"
  149. self.dps[POWER_DPS] = True
  150. async with assert_device_properties_set(
  151. self.subject._device, {HVACMODE_DPS: "Dehumidity", POWER_DPS: True}
  152. ):
  153. await self.subject.async_set_hvac_mode(HVACMode.DRY)
  154. async def test_set_mode_to_fan(self):
  155. self.dps[HVACMODE_DPS] = "Auto"
  156. self.dps[POWER_DPS] = True
  157. async with assert_device_properties_set(
  158. self.subject._device, {HVACMODE_DPS: "Fan", POWER_DPS: True}
  159. ):
  160. await self.subject.async_set_hvac_mode(HVACMode.FAN_ONLY)
  161. async def test_set_mode_to_auto(self):
  162. self.dps[HVACMODE_DPS] = "Fan"
  163. self.dps[POWER_DPS] = True
  164. async with assert_device_properties_set(
  165. self.subject._device, {HVACMODE_DPS: "Auto", POWER_DPS: True}
  166. ):
  167. await self.subject.async_set_hvac_mode(HVACMode.AUTO)
  168. def test_fan_mode(self):
  169. self.dps[FAN_DPS] = "Low"
  170. self.assertEqual(self.subject.fan_mode, "Low")
  171. self.dps[FAN_DPS] = "Medium"
  172. self.assertEqual(self.subject.fan_mode, "Medium")
  173. self.dps[FAN_DPS] = "High"
  174. self.assertEqual(self.subject.fan_mode, "High")
  175. def test_fan_mode_invalid_in_auto_hvac_mode(self):
  176. self.dps[HVACMODE_DPS] = "Auto"
  177. self.dps[FAN_DPS] = "Low"
  178. self.assertIs(self.subject.fan_mode, None)
  179. def test_fan_modes(self):
  180. self.assertCountEqual(
  181. self.subject.fan_modes,
  182. ["Low", "Medium", "High"],
  183. )
  184. async def test_set_fan_mode_to_low(self):
  185. async with assert_device_properties_set(self.subject._device, {FAN_DPS: "Low"}):
  186. await self.subject.async_set_fan_mode("Low")
  187. async def test_set_fan_mode_to_medium(self):
  188. async with assert_device_properties_set(
  189. self.subject._device, {FAN_DPS: "Medium"}
  190. ):
  191. await self.subject.async_set_fan_mode("Medium")
  192. async def test_set_fan_mode_to_high(self):
  193. async with assert_device_properties_set(
  194. self.subject._device, {FAN_DPS: "High"}
  195. ):
  196. await self.subject.async_set_fan_mode("High")
  197. def test_swing_modes(self):
  198. self.assertCountEqual(
  199. self.subject.swing_modes,
  200. ["off", "vertical"],
  201. )
  202. def test_swing_mode(self):
  203. self.dps[SWING_DPS] = False
  204. self.assertEqual(self.subject.swing_mode, "off")
  205. self.dps[SWING_DPS] = True
  206. self.assertEqual(self.subject.swing_mode, "vertical")
  207. async def test_set_swing_mode_to_vertical(self):
  208. async with assert_device_properties_set(
  209. self.subject._device,
  210. {SWING_DPS: True},
  211. ):
  212. await self.subject.async_set_swing_mode("vertical")
  213. async def test_set_swing_mode_to_off(self):
  214. async with assert_device_properties_set(
  215. self.subject._device,
  216. {SWING_DPS: False},
  217. ):
  218. await self.subject.async_set_swing_mode("off")
  219. def test_light_icon(self):
  220. self.assertEqual(self.basicLight.icon, "mdi:solar-power")
  221. def test_switch_icon(self):
  222. self.assertEqual(self.basicSwitch.icon, "mdi:creation")