test_electriq_cd25_dehumidifier.py 7.8 KB

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