test_electriq_cd20_dehumidifier.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. from homeassistant.components.fan import FanEntityFeature
  2. from homeassistant.components.humidifier import HumidifierEntityFeature
  3. from homeassistant.components.sensor import SensorDeviceClass
  4. from homeassistant.const import (
  5. PERCENTAGE,
  6. UnitOfTemperature,
  7. )
  8. from ..const import ELECTRIQ_CD20PRO_DEHUMIDIFIER_PAYLOAD
  9. from ..helpers import assert_device_properties_set
  10. from ..mixins.light import BasicLightTests
  11. from ..mixins.sensor import MultiSensorTests
  12. from ..mixins.switch import MultiSwitchTests, SwitchableTests
  13. from .base_device_tests import TuyaDeviceTestCase
  14. SWITCH_DPS = "1"
  15. MODE_DPS = "2"
  16. CURRENTHUMID_DPS = "3"
  17. HUMIDITY_DPS = "4"
  18. ANION_DPS = "5"
  19. UV_DPS = "10"
  20. LIGHT_DPS = "101"
  21. PRESET_DPS = "102"
  22. CURRENTTEMP_DPS = "103"
  23. class TestElectriqCD20ProDehumidifier(
  24. BasicLightTests,
  25. MultiSensorTests,
  26. MultiSwitchTests,
  27. SwitchableTests,
  28. TuyaDeviceTestCase,
  29. ):
  30. __test__ = True
  31. def setUp(self):
  32. self.setUpForConfig(
  33. "electriq_cd20pro_dehumidifier.yaml", ELECTRIQ_CD20PRO_DEHUMIDIFIER_PAYLOAD
  34. )
  35. self.subject = self.entities.get("humidifier")
  36. self.fan = self.entities.get("fan")
  37. self.setUpSwitchable(SWITCH_DPS, self.subject)
  38. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_display"))
  39. self.setUpMultiSwitch(
  40. [
  41. {"dps": UV_DPS, "name": "switch_uv_sterilization"},
  42. {"dps": ANION_DPS, "name": "switch_ionizer"},
  43. ]
  44. )
  45. self.setUpMultiSensors(
  46. [
  47. {
  48. "name": "sensor_current_temperature",
  49. "dps": CURRENTTEMP_DPS,
  50. "unit": UnitOfTemperature.CELSIUS,
  51. "device_class": SensorDeviceClass.TEMPERATURE,
  52. "state_class": "measurement",
  53. },
  54. {
  55. "name": "sensor_current_humidity",
  56. "dps": CURRENTHUMID_DPS,
  57. "unit": PERCENTAGE,
  58. "device_class": SensorDeviceClass.HUMIDITY,
  59. "state_class": "measurement",
  60. },
  61. ]
  62. )
  63. self.mark_secondary(["light_display"])
  64. def test_supported_features(self):
  65. self.assertEqual(self.subject.supported_features, HumidifierEntityFeature.MODES)
  66. self.assertEqual(self.fan.supported_features, FanEntityFeature.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_extra_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.extra_state_attributes,
  206. {"current_humidity": 50, "current_temperature": 21, "anion": True},
  207. )
  208. self.assertEqual(self.fan.extra_state_attributes, {})