test_electriq_cd20_dehumidifier.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. def test_supported_features(self):
  65. self.assertEqual(self.subject.supported_features, SUPPORT_MODES)
  66. self.assertEqual(self.fan.supported_features, SUPPORT_PRESET_MODE)
  67. def test_icon(self):
  68. """Test that the icon is as expected."""
  69. self.dps[SWITCH_DPS] = True
  70. self.dps[MODE_DPS] = "auto"
  71. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  72. self.dps[SWITCH_DPS] = False
  73. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  74. self.dps[MODE_DPS] = "fan"
  75. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  76. self.dps[SWITCH_DPS] = True
  77. self.assertEqual(self.subject.icon, "mdi:air-purifier")
  78. self.dps[MODE_DPS] = "high"
  79. self.assertEqual(self.subject.icon, "mdi:tshirt-crew-outline")
  80. self.assertEqual(
  81. self.multiSwitch["switch_uv_sterilization"].icon,
  82. "mdi:solar-power",
  83. )
  84. self.assertEqual(
  85. self.multiSwitch["switch_ionizer"].icon,
  86. "mdi:creation",
  87. )
  88. self.dps[LIGHT_DPS] = True
  89. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  90. self.dps[LIGHT_DPS] = False
  91. self.assertEqual(self.basicLight.icon, "mdi:led-off")
  92. def test_min_target_humidity(self):
  93. self.assertEqual(self.subject.min_humidity, 35)
  94. def test_max_target_humidity(self):
  95. self.assertEqual(self.subject.max_humidity, 80)
  96. def test_target_humidity(self):
  97. self.dps[HUMIDITY_DPS] = 55
  98. self.assertEqual(self.subject.target_humidity, 55)
  99. async def test_set_target_humidity_rounds_up_to_5_percent(self):
  100. async with assert_device_properties_set(
  101. self.subject._device,
  102. {HUMIDITY_DPS: 55},
  103. ):
  104. await self.subject.async_set_humidity(53)
  105. async def test_set_target_humidity_rounds_down_to_5_percent(self):
  106. async with assert_device_properties_set(
  107. self.subject._device,
  108. {HUMIDITY_DPS: 50},
  109. ):
  110. await self.subject.async_set_humidity(52)
  111. async def test_fan_turn_on(self):
  112. async with assert_device_properties_set(
  113. self.subject._device, {SWITCH_DPS: True}
  114. ):
  115. await self.fan.async_turn_on()
  116. async def test_fan_turn_off(self):
  117. async with assert_device_properties_set(
  118. self.subject._device, {SWITCH_DPS: False}
  119. ):
  120. await self.fan.async_turn_off()
  121. def test_mode(self):
  122. self.dps[MODE_DPS] = "low"
  123. self.assertEqual(self.subject.mode, "Low")
  124. self.dps[MODE_DPS] = "high"
  125. self.assertEqual(self.subject.mode, "High")
  126. self.dps[MODE_DPS] = "auto"
  127. self.assertEqual(self.subject.mode, "Auto")
  128. self.dps[MODE_DPS] = "fan"
  129. self.assertEqual(self.subject.mode, "Air clean")
  130. async def test_set_mode_to_auto(self):
  131. async with assert_device_properties_set(
  132. self.subject._device,
  133. {
  134. MODE_DPS: "auto",
  135. },
  136. ):
  137. await self.subject.async_set_mode("Auto")
  138. self.subject._device.anticipate_property_value.assert_not_called()
  139. async def test_set_mode_to_low(self):
  140. async with assert_device_properties_set(
  141. self.subject._device,
  142. {
  143. MODE_DPS: "low",
  144. },
  145. ):
  146. await self.subject.async_set_mode("Low")
  147. self.subject._device.anticipate_property_value.assert_not_called()
  148. async def test_set_mode_to_high(self):
  149. async with assert_device_properties_set(
  150. self.subject._device,
  151. {
  152. MODE_DPS: "high",
  153. },
  154. ):
  155. await self.subject.async_set_mode("High")
  156. self.subject._device.anticipate_property_value.assert_not_called()
  157. async def test_set_mode_to_fan(self):
  158. async with assert_device_properties_set(
  159. self.subject._device,
  160. {
  161. MODE_DPS: "fan",
  162. },
  163. ):
  164. await self.subject.async_set_mode("Air clean")
  165. self.subject._device.anticipate_property_value.assert_not_called()
  166. def test_fan_preset_mode(self):
  167. self.dps[PRESET_DPS] = "45"
  168. self.assertEqual(self.fan.preset_mode, "Half open")
  169. self.dps[PRESET_DPS] = "90"
  170. self.assertEqual(self.fan.preset_mode, "Fully open")
  171. self.dps[PRESET_DPS] = "0_90"
  172. self.assertEqual(self.fan.preset_mode, "Oscillate")
  173. async def test_set_fan_to_half_open(self):
  174. async with assert_device_properties_set(
  175. self.subject._device,
  176. {
  177. PRESET_DPS: "45",
  178. },
  179. ):
  180. await self.fan.async_set_preset_mode("Half open")
  181. self.subject._device.anticipate_property_value.assert_not_called()
  182. async def test_set_fan_to_fully_open(self):
  183. async with assert_device_properties_set(
  184. self.subject._device,
  185. {
  186. PRESET_DPS: "90",
  187. },
  188. ):
  189. await self.fan.async_set_preset_mode("Fully open")
  190. self.subject._device.anticipate_property_value.assert_not_called()
  191. async def test_set_fan_to_oscillate(self):
  192. async with assert_device_properties_set(
  193. self.subject._device,
  194. {
  195. PRESET_DPS: "0_90",
  196. },
  197. ):
  198. await self.fan.async_set_preset_mode("Oscillate")
  199. self.subject._device.anticipate_property_value.assert_not_called()
  200. def test_state_attributes(self):
  201. self.dps[CURRENTHUMID_DPS] = 50
  202. self.dps[CURRENTTEMP_DPS] = 21
  203. self.dps[ANION_DPS] = True
  204. self.assertDictEqual(
  205. self.subject.device_state_attributes,
  206. {"current_humidity": 50, "current_temperature": 21, "anion": True},
  207. )
  208. self.assertEqual(self.fan.device_state_attributes, {})