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