test_electriq_cd25_dehumidifier.py 6.9 KB

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