test_eanons_humidifier.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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")
  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_min_target_humidity(self):
  79. self.assertEqual(self.subject.min_humidity, 40)
  80. def test_max_target_humidity(self):
  81. self.assertEqual(self.subject.max_humidity, 90)
  82. def test_target_humidity(self):
  83. self.dps[HUMIDITY_DPS] = 55
  84. self.assertEqual(self.subject.target_humidity, 55)
  85. async def test_fan_turn_on(self):
  86. async with assert_device_properties_set(
  87. self.subject._device, {HVACMODE_DPS: True}
  88. ):
  89. await self.fan.async_turn_on()
  90. async def test_fan_turn_off(self):
  91. async with assert_device_properties_set(
  92. self.subject._device, {HVACMODE_DPS: False}
  93. ):
  94. await self.fan.async_turn_off()
  95. def test_preset_mode(self):
  96. self.dps[PRESET_DPS] = "sleep"
  97. self.assertEqual(self.subject.mode, MODE_SLEEP)
  98. self.dps[PRESET_DPS] = "humidity"
  99. self.assertEqual(self.subject.mode, MODE_AUTO)
  100. self.dps[PRESET_DPS] = "work"
  101. self.assertEqual(self.subject.mode, MODE_NORMAL)
  102. self.dps[PRESET_DPS] = None
  103. self.assertEqual(self.subject.mode, None)
  104. def test_preset_modes(self):
  105. self.assertCountEqual(
  106. self.subject.available_modes,
  107. [MODE_NORMAL, MODE_SLEEP, MODE_AUTO],
  108. )
  109. async def test_set_mode_to_auto(self):
  110. async with assert_device_properties_set(
  111. self.subject._device,
  112. {
  113. PRESET_DPS: "humidity",
  114. },
  115. ):
  116. await self.subject.async_set_mode(MODE_AUTO)
  117. self.subject._device.anticipate_property_value.assert_not_called()
  118. async def test_set_mode_to_sleep(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {
  122. PRESET_DPS: "sleep",
  123. },
  124. ):
  125. await self.subject.async_set_mode(MODE_SLEEP)
  126. self.subject._device.anticipate_property_value.assert_not_called()
  127. async def test_set_mode_to_normal(self):
  128. async with assert_device_properties_set(
  129. self.subject._device,
  130. {
  131. PRESET_DPS: "work",
  132. },
  133. ):
  134. await self.subject.async_set_mode(MODE_NORMAL)
  135. self.subject._device.anticipate_property_value.assert_not_called()
  136. def test_extra_state_attributes(self):
  137. self.dps[ERROR_DPS] = 0
  138. self.dps[TIMERHR_DPS] = "cancel"
  139. self.dps[TIMER_DPS] = 0
  140. self.dps[CURRENTHUMID_DPS] = 50
  141. self.dps[FANMODE_DPS] = "middle"
  142. self.assertDictEqual(
  143. self.subject.extra_state_attributes,
  144. {
  145. "error": "OK",
  146. "timer_hr": "cancel",
  147. "timer_min": 0,
  148. "current_humidity": 50,
  149. },
  150. )
  151. def test_fan_speed(self):
  152. self.dps[FANMODE_DPS] = "small"
  153. self.assertEqual(self.fan.percentage, 33)
  154. self.dps[FANMODE_DPS] = "middle"
  155. self.assertEqual(self.fan.percentage, 67)
  156. self.dps[FANMODE_DPS] = "large"
  157. self.assertEqual(self.fan.percentage, 100)
  158. def test_fan_speed_count(self):
  159. self.assertEqual(self.fan.speed_count, 3)
  160. def test_fan_percentage_step(self):
  161. self.assertAlmostEqual(self.fan.percentage_step, 33, 0)
  162. async def test_fan_set_speed(self):
  163. async with assert_device_properties_set(
  164. self.fan._device,
  165. {FANMODE_DPS: "small"},
  166. ):
  167. await self.fan.async_set_percentage(33)
  168. async def test_fan_set_speed_snaps(self):
  169. async with assert_device_properties_set(
  170. self.fan._device,
  171. {FANMODE_DPS: "middle"},
  172. ):
  173. await self.fan.async_set_percentage(60)