test_eanons_humidifier.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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": "cancel",
  41. "1": "1h",
  42. "2": "2h",
  43. "3": "3h",
  44. "4": "4h",
  45. "5": "5h",
  46. "6": "6h",
  47. "7": "7h",
  48. "8": "8h",
  49. "9": "9h",
  50. "10": "10h",
  51. "11": "11h",
  52. "12": "12h",
  53. },
  54. )
  55. self.setUpBasicSensor(
  56. TIMER_DPS,
  57. self.entities.get("sensor_time_remaining"),
  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. [
  68. "select_timer",
  69. "sensor_time_remaining",
  70. "binary_sensor_tank_empty",
  71. ]
  72. )
  73. def test_supported_features(self):
  74. self.assertEqual(
  75. self.subject.supported_features,
  76. HumidifierEntityFeature.MODES,
  77. )
  78. self.assertEqual(
  79. self.fan.supported_features,
  80. FanEntityFeature.SET_SPEED
  81. | FanEntityFeature.TURN_OFF
  82. | FanEntityFeature.TURN_ON,
  83. )
  84. def test_current_humidity(self):
  85. self.dps[CURRENTHUMID_DPS] = 75
  86. self.assertEqual(self.subject.current_humidity, 75)
  87. def test_min_target_humidity(self):
  88. self.assertEqual(self.subject.min_humidity, 40)
  89. def test_max_target_humidity(self):
  90. self.assertEqual(self.subject.max_humidity, 90)
  91. def test_target_humidity(self):
  92. self.dps[HUMIDITY_DPS] = 55
  93. self.assertEqual(self.subject.target_humidity, 55)
  94. async def test_fan_turn_on(self):
  95. async with assert_device_properties_set(
  96. self.subject._device, {HVACMODE_DPS: True}
  97. ):
  98. await self.fan.async_turn_on()
  99. async def test_fan_turn_off(self):
  100. async with assert_device_properties_set(
  101. self.subject._device, {HVACMODE_DPS: False}
  102. ):
  103. await self.fan.async_turn_off()
  104. def test_preset_mode(self):
  105. self.dps[PRESET_DPS] = "sleep"
  106. self.assertEqual(self.subject.mode, MODE_SLEEP)
  107. self.dps[PRESET_DPS] = "humidity"
  108. self.assertEqual(self.subject.mode, MODE_AUTO)
  109. self.dps[PRESET_DPS] = "work"
  110. self.assertEqual(self.subject.mode, MODE_NORMAL)
  111. self.dps[PRESET_DPS] = None
  112. self.assertEqual(self.subject.mode, None)
  113. def test_preset_modes(self):
  114. self.assertCountEqual(
  115. self.subject.available_modes,
  116. [MODE_NORMAL, MODE_SLEEP, MODE_AUTO],
  117. )
  118. async def test_set_mode_to_auto(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {
  122. PRESET_DPS: "humidity",
  123. },
  124. ):
  125. await self.subject.async_set_mode(MODE_AUTO)
  126. self.subject._device.anticipate_property_value.assert_not_called()
  127. async def test_set_mode_to_sleep(self):
  128. async with assert_device_properties_set(
  129. self.subject._device,
  130. {
  131. PRESET_DPS: "sleep",
  132. },
  133. ):
  134. await self.subject.async_set_mode(MODE_SLEEP)
  135. self.subject._device.anticipate_property_value.assert_not_called()
  136. async def test_set_mode_to_normal(self):
  137. async with assert_device_properties_set(
  138. self.subject._device,
  139. {
  140. PRESET_DPS: "work",
  141. },
  142. ):
  143. await self.subject.async_set_mode(MODE_NORMAL)
  144. self.subject._device.anticipate_property_value.assert_not_called()
  145. def test_extra_state_attributes(self):
  146. self.dps[ERROR_DPS] = 0
  147. self.dps[TIMERHR_DPS] = "cancel"
  148. self.dps[TIMER_DPS] = 0
  149. self.dps[FANMODE_DPS] = "middle"
  150. self.assertDictEqual(
  151. self.subject.extra_state_attributes,
  152. {
  153. "error": "OK",
  154. "timer_hr": "cancel",
  155. "timer_min": 0,
  156. },
  157. )
  158. def test_fan_speed(self):
  159. self.dps[FANMODE_DPS] = "small"
  160. self.assertEqual(self.fan.percentage, 33)
  161. self.dps[FANMODE_DPS] = "middle"
  162. self.assertEqual(self.fan.percentage, 67)
  163. self.dps[FANMODE_DPS] = "large"
  164. self.assertEqual(self.fan.percentage, 100)
  165. def test_fan_speed_count(self):
  166. self.assertEqual(self.fan.speed_count, 3)
  167. def test_fan_percentage_step(self):
  168. self.assertAlmostEqual(self.fan.percentage_step, 33, 0)
  169. async def test_fan_set_speed(self):
  170. async with assert_device_properties_set(
  171. self.fan._device,
  172. {FANMODE_DPS: "small"},
  173. ):
  174. await self.fan.async_set_percentage(33)
  175. async def test_fan_set_speed_snaps(self):
  176. async with assert_device_properties_set(
  177. self.fan._device,
  178. {FANMODE_DPS: "middle"},
  179. ):
  180. await self.fan.async_set_percentage(60)