test_eanons_humidifier.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.fan import FanEntityFeature
  3. from homeassistant.components.humidifier import HumidifierEntityFeature
  4. from homeassistant.components.humidifier.const import (
  5. MODE_NORMAL,
  6. MODE_AUTO,
  7. MODE_SLEEP,
  8. )
  9. from homeassistant.components.sensor import SensorDeviceClass
  10. from ..const import EANONS_HUMIDIFIER_PAYLOAD
  11. from ..helpers import assert_device_properties_set
  12. from ..mixins.binary_sensor import BasicBinarySensorTests
  13. from ..mixins.select import BasicSelectTests
  14. from ..mixins.sensor import BasicSensorTests
  15. from ..mixins.switch import BasicSwitchTests, SwitchableTests
  16. from .base_device_tests import TuyaDeviceTestCase
  17. FANMODE_DPS = "2"
  18. TIMERHR_DPS = "3"
  19. TIMER_DPS = "4"
  20. ERROR_DPS = "9"
  21. HVACMODE_DPS = "10"
  22. PRESET_DPS = "12"
  23. HUMIDITY_DPS = "15"
  24. CURRENTHUMID_DPS = "16"
  25. SWITCH_DPS = "22"
  26. class TestEanonsHumidifier(
  27. BasicBinarySensorTests,
  28. BasicSelectTests,
  29. BasicSensorTests,
  30. BasicSwitchTests,
  31. SwitchableTests,
  32. TuyaDeviceTestCase,
  33. ):
  34. __test__ = True
  35. def setUp(self):
  36. self.setUpForConfig("eanons_humidifier.yaml", EANONS_HUMIDIFIER_PAYLOAD)
  37. self.subject = self.entities.get("humidifier")
  38. self.setUpSwitchable(HVACMODE_DPS, self.subject)
  39. self.fan = self.entities.get("fan_intensity")
  40. self.setUpBasicSwitch(SWITCH_DPS, self.entities.get("switch_uv_sterilization"))
  41. self.setUpBasicSelect(
  42. TIMERHR_DPS,
  43. self.entities.get("select_timer"),
  44. {
  45. "cancel": "Off",
  46. "1": "1 hour",
  47. "2": "2 hours",
  48. "3": "3 hours",
  49. "4": "4 hours",
  50. "5": "5 hours",
  51. "6": "6 hours",
  52. "7": "7 hours",
  53. "8": "8 hours",
  54. "9": "9 hours",
  55. "10": "10 hours",
  56. "11": "11 hours",
  57. "12": "12 hours",
  58. },
  59. )
  60. self.setUpBasicSensor(
  61. TIMER_DPS,
  62. self.entities.get("sensor_timer"),
  63. unit="min",
  64. device_class=SensorDeviceClass.DURATION,
  65. )
  66. self.setUpBasicBinarySensor(
  67. ERROR_DPS,
  68. self.entities.get("binary_sensor_tank"),
  69. device_class=BinarySensorDeviceClass.PROBLEM,
  70. testdata=(1, 0),
  71. )
  72. self.mark_secondary(["select_timer", "sensor_timer", "binary_sensor_tank"])
  73. def test_supported_features(self):
  74. self.assertEqual(self.subject.supported_features, HumidifierEntityFeature.MODES)
  75. self.assertEqual(self.fan.supported_features, FanEntityFeature.SET_SPEED)
  76. def test_icon_is_humidifier(self):
  77. """Test that the icon is as expected."""
  78. self.dps[HVACMODE_DPS] = True
  79. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  80. self.dps[HVACMODE_DPS] = False
  81. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  82. def test_min_target_humidity(self):
  83. self.assertEqual(self.subject.min_humidity, 40)
  84. def test_max_target_humidity(self):
  85. self.assertEqual(self.subject.max_humidity, 90)
  86. def test_target_humidity(self):
  87. self.dps[HUMIDITY_DPS] = 55
  88. self.assertEqual(self.subject.target_humidity, 55)
  89. async def test_fan_turn_on(self):
  90. async with assert_device_properties_set(
  91. self.subject._device, {HVACMODE_DPS: True}
  92. ):
  93. await self.fan.async_turn_on()
  94. async def test_fan_turn_off(self):
  95. async with assert_device_properties_set(
  96. self.subject._device, {HVACMODE_DPS: False}
  97. ):
  98. await self.fan.async_turn_off()
  99. def test_preset_mode(self):
  100. self.dps[PRESET_DPS] = "sleep"
  101. self.assertEqual(self.subject.mode, MODE_SLEEP)
  102. self.dps[PRESET_DPS] = "humidity"
  103. self.assertEqual(self.subject.mode, MODE_AUTO)
  104. self.dps[PRESET_DPS] = "work"
  105. self.assertEqual(self.subject.mode, MODE_NORMAL)
  106. self.dps[PRESET_DPS] = None
  107. self.assertEqual(self.subject.mode, None)
  108. def test_preset_modes(self):
  109. self.assertCountEqual(
  110. self.subject.available_modes,
  111. [MODE_NORMAL, MODE_SLEEP, MODE_AUTO],
  112. )
  113. async def test_set_mode_to_auto(self):
  114. async with assert_device_properties_set(
  115. self.subject._device,
  116. {
  117. PRESET_DPS: "humidity",
  118. },
  119. ):
  120. await self.subject.async_set_mode(MODE_AUTO)
  121. self.subject._device.anticipate_property_value.assert_not_called()
  122. async def test_set_mode_to_sleep(self):
  123. async with assert_device_properties_set(
  124. self.subject._device,
  125. {
  126. PRESET_DPS: "sleep",
  127. },
  128. ):
  129. await self.subject.async_set_mode(MODE_SLEEP)
  130. self.subject._device.anticipate_property_value.assert_not_called()
  131. async def test_set_mode_to_normal(self):
  132. async with assert_device_properties_set(
  133. self.subject._device,
  134. {
  135. PRESET_DPS: "work",
  136. },
  137. ):
  138. await self.subject.async_set_mode(MODE_NORMAL)
  139. self.subject._device.anticipate_property_value.assert_not_called()
  140. def test_extra_state_attributes(self):
  141. self.dps[ERROR_DPS] = 0
  142. self.dps[TIMERHR_DPS] = "cancel"
  143. self.dps[TIMER_DPS] = 0
  144. self.dps[CURRENTHUMID_DPS] = 50
  145. self.dps[FANMODE_DPS] = "middle"
  146. self.assertDictEqual(
  147. self.subject.extra_state_attributes,
  148. {
  149. "error": "OK",
  150. "timer_hr": "cancel",
  151. "timer_min": 0,
  152. "current_humidity": 50,
  153. },
  154. )
  155. def test_fan_speed(self):
  156. self.dps[FANMODE_DPS] = "small"
  157. self.assertEqual(self.fan.percentage, 33)
  158. self.dps[FANMODE_DPS] = "middle"
  159. self.assertEqual(self.fan.percentage, 67)
  160. self.dps[FANMODE_DPS] = "large"
  161. self.assertEqual(self.fan.percentage, 100)
  162. def test_fan_speed_count(self):
  163. self.assertEqual(self.fan.speed_count, 3)
  164. def test_fan_percentage_step(self):
  165. self.assertAlmostEqual(self.fan.percentage_step, 33, 0)
  166. async def test_fan_set_speed(self):
  167. async with assert_device_properties_set(
  168. self.fan._device,
  169. {FANMODE_DPS: "small"},
  170. ):
  171. await self.fan.async_set_percentage(33)
  172. async def test_fan_set_speed_snaps(self):
  173. async with assert_device_properties_set(
  174. self.fan._device,
  175. {FANMODE_DPS: "middle"},
  176. ):
  177. await self.fan.async_set_percentage(60)