4
0

test_eanons_humidifier.py 6.5 KB

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