test_electriq_cd25_dehumidifier.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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_DEHUMIDIFIER_PAYLOAD
  9. from ..helpers import assert_device_properties_set
  10. from ..mixins.light import BasicLightTests
  11. from ..mixins.lock import BasicLockTests
  12. from ..mixins.sensor import MultiSensorTests
  13. from ..mixins.switch import BasicSwitchTests, 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. LOCK_DPS = "7"
  20. LIGHT_DPS = "10"
  21. PRESET_DPS = "102"
  22. CURRENTTEMP_DPS = "103"
  23. IONIZER_DPS = "104"
  24. class TestElectriqCD25ProDehumidifier(
  25. BasicLightTests,
  26. BasicLockTests,
  27. BasicSwitchTests,
  28. MultiSensorTests,
  29. SwitchableTests,
  30. TuyaDeviceTestCase,
  31. ):
  32. __test__ = True
  33. def setUp(self):
  34. self.setUpForConfig(
  35. "electriq_cd25pro_dehumidifier.yaml", ELECTRIQ_DEHUMIDIFIER_PAYLOAD
  36. )
  37. self.subject = self.entities.get("humidifier")
  38. self.fan = self.entities.get("fan")
  39. self.setUpSwitchable(SWITCH_DPS, self.subject)
  40. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_uv_sterilization"))
  41. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  42. self.setUpBasicSwitch(IONIZER_DPS, self.entities.get("switch_ionizer"))
  43. self.setUpMultiSensors(
  44. [
  45. {
  46. "name": "sensor_current_temperature",
  47. "dps": CURRENTTEMP_DPS,
  48. "unit": UnitOfTemperature.CELSIUS,
  49. "device_class": SensorDeviceClass.TEMPERATURE,
  50. "state_class": "measurement",
  51. },
  52. {
  53. "name": "sensor_current_humidity",
  54. "dps": CURRENTHUMID_DPS,
  55. "unit": PERCENTAGE,
  56. "device_class": SensorDeviceClass.HUMIDITY,
  57. "state_class": "measurement",
  58. },
  59. ]
  60. )
  61. self.mark_secondary(["lock_child_lock"])
  62. def test_supported_features(self):
  63. self.assertEqual(self.subject.supported_features, HumidifierEntityFeature.MODES)
  64. self.assertEqual(self.fan.supported_features, FanEntityFeature.PRESET_MODE)
  65. def test_icon(self):
  66. """Test that the icon is as expected."""
  67. self.dps[SWITCH_DPS] = True
  68. self.dps[MODE_DPS] = "auto"
  69. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  70. self.dps[SWITCH_DPS] = False
  71. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  72. self.dps[MODE_DPS] = "fan"
  73. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  74. self.dps[SWITCH_DPS] = True
  75. self.assertEqual(self.subject.icon, "mdi:air-purifier")
  76. self.dps[MODE_DPS] = "high"
  77. self.assertEqual(self.subject.icon, "mdi:tshirt-crew-outline")
  78. self.assertEqual(self.basicLight.icon, "mdi:solar-power")
  79. self.assertEqual(self.basicSwitch.icon, "mdi:creation")
  80. def test_min_target_humidity(self):
  81. self.assertEqual(self.subject.min_humidity, 35)
  82. def test_max_target_humidity(self):
  83. self.assertEqual(self.subject.max_humidity, 80)
  84. def test_target_humidity(self):
  85. self.dps[HUMIDITY_DPS] = 55
  86. self.assertEqual(self.subject.target_humidity, 55)
  87. async def test_set_target_humidity_rounds_up_to_5_percent(self):
  88. async with assert_device_properties_set(
  89. self.subject._device,
  90. {HUMIDITY_DPS: 55},
  91. ):
  92. await self.subject.async_set_humidity(53)
  93. async def test_set_target_humidity_rounds_down_to_5_percent(self):
  94. async with assert_device_properties_set(
  95. self.subject._device,
  96. {HUMIDITY_DPS: 50},
  97. ):
  98. await self.subject.async_set_humidity(52)
  99. async def test_fan_turn_on(self):
  100. async with assert_device_properties_set(
  101. self.subject._device, {SWITCH_DPS: True}
  102. ):
  103. await self.fan.async_turn_on()
  104. async def test_fan_turn_off(self):
  105. async with assert_device_properties_set(
  106. self.subject._device, {SWITCH_DPS: False}
  107. ):
  108. await self.fan.async_turn_off()
  109. def test_mode(self):
  110. self.dps[MODE_DPS] = "low"
  111. self.assertEqual(self.subject.mode, "Low")
  112. self.dps[MODE_DPS] = "high"
  113. self.assertEqual(self.subject.mode, "High")
  114. self.dps[MODE_DPS] = "auto"
  115. self.assertEqual(self.subject.mode, "Auto")
  116. self.dps[MODE_DPS] = "fan"
  117. self.assertEqual(self.subject.mode, "Air clean")
  118. async def test_set_mode_to_auto(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {
  122. MODE_DPS: "auto",
  123. },
  124. ):
  125. await self.subject.async_set_mode("Auto")
  126. self.subject._device.anticipate_property_value.assert_not_called()
  127. async def test_set_mode_to_low(self):
  128. async with assert_device_properties_set(
  129. self.subject._device,
  130. {
  131. MODE_DPS: "low",
  132. },
  133. ):
  134. await self.subject.async_set_mode("Low")
  135. self.subject._device.anticipate_property_value.assert_not_called()
  136. async def test_set_mode_to_high(self):
  137. async with assert_device_properties_set(
  138. self.subject._device,
  139. {
  140. MODE_DPS: "high",
  141. },
  142. ):
  143. await self.subject.async_set_mode("High")
  144. self.subject._device.anticipate_property_value.assert_not_called()
  145. async def test_set_mode_to_fan(self):
  146. async with assert_device_properties_set(
  147. self.subject._device,
  148. {
  149. MODE_DPS: "fan",
  150. },
  151. ):
  152. await self.subject.async_set_mode("Air clean")
  153. self.subject._device.anticipate_property_value.assert_not_called()
  154. def test_fan_preset_mode(self):
  155. self.dps[PRESET_DPS] = "45"
  156. self.assertEqual(self.fan.preset_mode, "Half open")
  157. self.dps[PRESET_DPS] = "90"
  158. self.assertEqual(self.fan.preset_mode, "Fully open")
  159. self.dps[PRESET_DPS] = "0_90"
  160. self.assertEqual(self.fan.preset_mode, "Oscillate")
  161. async def test_set_fan_to_half_open(self):
  162. async with assert_device_properties_set(
  163. self.subject._device,
  164. {
  165. PRESET_DPS: "45",
  166. },
  167. ):
  168. await self.fan.async_set_preset_mode("Half open")
  169. self.subject._device.anticipate_property_value.assert_not_called()
  170. async def test_set_fan_to_fully_open(self):
  171. async with assert_device_properties_set(
  172. self.subject._device,
  173. {
  174. PRESET_DPS: "90",
  175. },
  176. ):
  177. await self.fan.async_set_preset_mode("Fully open")
  178. self.subject._device.anticipate_property_value.assert_not_called()
  179. async def test_set_fan_to_oscillate(self):
  180. async with assert_device_properties_set(
  181. self.subject._device,
  182. {
  183. PRESET_DPS: "0_90",
  184. },
  185. ):
  186. await self.fan.async_set_preset_mode("Oscillate")
  187. self.subject._device.anticipate_property_value.assert_not_called()
  188. def test_extra_state_attributes(self):
  189. self.dps[CURRENTHUMID_DPS] = 50
  190. self.dps[CURRENTTEMP_DPS] = 21
  191. self.assertDictEqual(
  192. self.subject.extra_state_attributes,
  193. {"current_humidity": 50, "current_temperature": 21},
  194. )
  195. self.assertEqual(self.fan.extra_state_attributes, {})