4
0

test_eanons_humidifier.py 6.7 KB

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