test_electriq_cd20_dehumidifier.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. from homeassistant.components.fan import SUPPORT_PRESET_MODE
  2. from homeassistant.components.humidifier import SUPPORT_MODES
  3. from homeassistant.const import (
  4. DEVICE_CLASS_HUMIDITY,
  5. DEVICE_CLASS_TEMPERATURE,
  6. PERCENTAGE,
  7. TEMP_CELSIUS,
  8. )
  9. from ..const import ELECTRIQ_CD20PRO_DEHUMIDIFIER_PAYLOAD
  10. from ..helpers import assert_device_properties_set
  11. from ..mixins.light import BasicLightTests
  12. from ..mixins.sensor import MultiSensorTests
  13. from ..mixins.switch import MultiSwitchTests, SwitchableTests
  14. from .base_device_tests import TuyaDeviceTestCase
  15. SWITCH_DPS = "1"
  16. MODE_DPS = "2"
  17. CURRENTHUMID_DPS = "3"
  18. HUMIDITY_DPS = "4"
  19. ANION_DPS = "5"
  20. UV_DPS = "10"
  21. LIGHT_DPS = "101"
  22. PRESET_DPS = "102"
  23. CURRENTTEMP_DPS = "103"
  24. class TestElectriqCD20ProDehumidifier(
  25. BasicLightTests,
  26. MultiSensorTests,
  27. MultiSwitchTests,
  28. SwitchableTests,
  29. TuyaDeviceTestCase,
  30. ):
  31. __test__ = True
  32. def setUp(self):
  33. self.setUpForConfig(
  34. "electriq_cd20pro_dehumidifier.yaml", ELECTRIQ_CD20PRO_DEHUMIDIFIER_PAYLOAD
  35. )
  36. self.subject = self.entities.get("humidifier")
  37. self.fan = self.entities.get("fan")
  38. self.setUpSwitchable(SWITCH_DPS, self.subject)
  39. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_display"))
  40. self.setUpMultiSwitch(
  41. [
  42. {"dps": UV_DPS, "name": "switch_uv_sterilization"},
  43. {"dps": ANION_DPS, "name": "switch_ionizer"},
  44. ]
  45. )
  46. self.setUpMultiSensors(
  47. [
  48. {
  49. "name": "sensor_current_temperature",
  50. "dps": CURRENTTEMP_DPS,
  51. "unit": TEMP_CELSIUS,
  52. "device_class": DEVICE_CLASS_TEMPERATURE,
  53. "state_class": "measurement",
  54. },
  55. {
  56. "name": "sensor_current_humidity",
  57. "dps": CURRENTHUMID_DPS,
  58. "unit": PERCENTAGE,
  59. "device_class": DEVICE_CLASS_HUMIDITY,
  60. "state_class": "measurement",
  61. },
  62. ]
  63. )
  64. self.mark_secondary(["light_display"])
  65. def test_supported_features(self):
  66. self.assertEqual(self.subject.supported_features, SUPPORT_MODES)
  67. self.assertEqual(self.fan.supported_features, SUPPORT_PRESET_MODE)
  68. def test_icon(self):
  69. """Test that the icon is as expected."""
  70. self.dps[SWITCH_DPS] = True
  71. self.dps[MODE_DPS] = "auto"
  72. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  73. self.dps[SWITCH_DPS] = False
  74. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  75. self.dps[MODE_DPS] = "fan"
  76. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  77. self.dps[SWITCH_DPS] = True
  78. self.assertEqual(self.subject.icon, "mdi:air-purifier")
  79. self.dps[MODE_DPS] = "high"
  80. self.assertEqual(self.subject.icon, "mdi:tshirt-crew-outline")
  81. self.assertEqual(
  82. self.multiSwitch["switch_uv_sterilization"].icon,
  83. "mdi:solar-power",
  84. )
  85. self.assertEqual(
  86. self.multiSwitch["switch_ionizer"].icon,
  87. "mdi:creation",
  88. )
  89. self.dps[LIGHT_DPS] = True
  90. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  91. self.dps[LIGHT_DPS] = False
  92. self.assertEqual(self.basicLight.icon, "mdi:led-off")
  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] = 55
  99. self.assertEqual(self.subject.target_humidity, 55)
  100. async def test_set_target_humidity_rounds_up_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 def test_set_target_humidity_rounds_down_to_5_percent(self):
  107. async with assert_device_properties_set(
  108. self.subject._device,
  109. {HUMIDITY_DPS: 50},
  110. ):
  111. await self.subject.async_set_humidity(52)
  112. async def test_fan_turn_on(self):
  113. async with assert_device_properties_set(
  114. self.subject._device, {SWITCH_DPS: True}
  115. ):
  116. await self.fan.async_turn_on()
  117. async def test_fan_turn_off(self):
  118. async with assert_device_properties_set(
  119. self.subject._device, {SWITCH_DPS: False}
  120. ):
  121. await self.fan.async_turn_off()
  122. def test_mode(self):
  123. self.dps[MODE_DPS] = "low"
  124. self.assertEqual(self.subject.mode, "Low")
  125. self.dps[MODE_DPS] = "high"
  126. self.assertEqual(self.subject.mode, "High")
  127. self.dps[MODE_DPS] = "auto"
  128. self.assertEqual(self.subject.mode, "Auto")
  129. self.dps[MODE_DPS] = "fan"
  130. self.assertEqual(self.subject.mode, "Air clean")
  131. async def test_set_mode_to_auto(self):
  132. async with assert_device_properties_set(
  133. self.subject._device,
  134. {
  135. MODE_DPS: "auto",
  136. },
  137. ):
  138. await self.subject.async_set_mode("Auto")
  139. self.subject._device.anticipate_property_value.assert_not_called()
  140. async def test_set_mode_to_low(self):
  141. async with assert_device_properties_set(
  142. self.subject._device,
  143. {
  144. MODE_DPS: "low",
  145. },
  146. ):
  147. await self.subject.async_set_mode("Low")
  148. self.subject._device.anticipate_property_value.assert_not_called()
  149. async def test_set_mode_to_high(self):
  150. async with assert_device_properties_set(
  151. self.subject._device,
  152. {
  153. MODE_DPS: "high",
  154. },
  155. ):
  156. await self.subject.async_set_mode("High")
  157. self.subject._device.anticipate_property_value.assert_not_called()
  158. async def test_set_mode_to_fan(self):
  159. async with assert_device_properties_set(
  160. self.subject._device,
  161. {
  162. MODE_DPS: "fan",
  163. },
  164. ):
  165. await self.subject.async_set_mode("Air clean")
  166. self.subject._device.anticipate_property_value.assert_not_called()
  167. def test_fan_preset_mode(self):
  168. self.dps[PRESET_DPS] = "45"
  169. self.assertEqual(self.fan.preset_mode, "Half open")
  170. self.dps[PRESET_DPS] = "90"
  171. self.assertEqual(self.fan.preset_mode, "Fully open")
  172. self.dps[PRESET_DPS] = "0_90"
  173. self.assertEqual(self.fan.preset_mode, "Oscillate")
  174. async def test_set_fan_to_half_open(self):
  175. async with assert_device_properties_set(
  176. self.subject._device,
  177. {
  178. PRESET_DPS: "45",
  179. },
  180. ):
  181. await self.fan.async_set_preset_mode("Half open")
  182. self.subject._device.anticipate_property_value.assert_not_called()
  183. async def test_set_fan_to_fully_open(self):
  184. async with assert_device_properties_set(
  185. self.subject._device,
  186. {
  187. PRESET_DPS: "90",
  188. },
  189. ):
  190. await self.fan.async_set_preset_mode("Fully open")
  191. self.subject._device.anticipate_property_value.assert_not_called()
  192. async def test_set_fan_to_oscillate(self):
  193. async with assert_device_properties_set(
  194. self.subject._device,
  195. {
  196. PRESET_DPS: "0_90",
  197. },
  198. ):
  199. await self.fan.async_set_preset_mode("Oscillate")
  200. self.subject._device.anticipate_property_value.assert_not_called()
  201. def test_extra_state_attributes(self):
  202. self.dps[CURRENTHUMID_DPS] = 50
  203. self.dps[CURRENTTEMP_DPS] = 21
  204. self.dps[ANION_DPS] = True
  205. self.assertDictEqual(
  206. self.subject.extra_state_attributes,
  207. {"current_humidity": 50, "current_temperature": 21, "anion": True},
  208. )
  209. self.assertEqual(self.fan.extra_state_attributes, {})