test_wetair_wawh1210lw_humidifier.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. from homeassistant.components.humidifier.const import (
  2. MODE_AUTO,
  3. MODE_BOOST,
  4. MODE_NORMAL,
  5. MODE_SLEEP,
  6. SUPPORT_MODES,
  7. )
  8. from homeassistant.components.sensor import SensorDeviceClass
  9. from homeassistant.const import (
  10. PERCENTAGE,
  11. STATE_UNAVAILABLE,
  12. )
  13. from ..const import WETAIR_WAWH1210_HUMIDIFIER_PAYLOAD
  14. from ..helpers import assert_device_properties_set
  15. from ..mixins.light import BasicLightTests
  16. from ..mixins.lock import BasicLockTests
  17. from ..mixins.sensor import MultiSensorTests
  18. from ..mixins.switch import MultiSwitchTests, SwitchableTests
  19. from .base_device_tests import TuyaDeviceTestCase
  20. SWITCH_DPS = "1"
  21. LIGHT_DPS = "5"
  22. SOUND_DPS = "8"
  23. HUMIDITY_DPS = "13"
  24. CURRENTHUMID_DPS = "14"
  25. UNKNOWN22_DPS = "22"
  26. PRESET_DPS = "24"
  27. IONIZER_DPS = "25"
  28. LOCK_DPS = "29"
  29. LEVEL_DPS = "101"
  30. class TestWetairWAWH1210LWHumidifier(
  31. BasicLightTests,
  32. BasicLockTests,
  33. MultiSensorTests,
  34. MultiSwitchTests,
  35. SwitchableTests,
  36. TuyaDeviceTestCase,
  37. ):
  38. __test__ = True
  39. def setUp(self):
  40. self.setUpForConfig(
  41. "wetair_wawh1210lw_humidifier.yaml", WETAIR_WAWH1210_HUMIDIFIER_PAYLOAD
  42. )
  43. self.subject = self.entities.get("humidifier")
  44. self.setUpSwitchable(SWITCH_DPS, self.subject)
  45. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_display"))
  46. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  47. self.setUpMultiSensors(
  48. [
  49. {
  50. "dps": CURRENTHUMID_DPS,
  51. "name": "sensor_current_humidity",
  52. "device_class": SensorDeviceClass.HUMIDITY,
  53. "state_class": "measurement",
  54. "unit": PERCENTAGE,
  55. },
  56. {
  57. "dps": LEVEL_DPS,
  58. "name": "sensor_water_level",
  59. "unit": PERCENTAGE,
  60. },
  61. ]
  62. )
  63. self.setUpMultiSwitch(
  64. [
  65. {
  66. "dps": SOUND_DPS,
  67. "name": "switch_sound",
  68. },
  69. {
  70. "dps": IONIZER_DPS,
  71. "name": "switch_ionizer",
  72. },
  73. ]
  74. )
  75. self.mark_secondary(
  76. [
  77. "light_display",
  78. "lock_child_lock",
  79. "sensor_water_level",
  80. "switch_sound",
  81. ]
  82. )
  83. def test_supported_features(self):
  84. self.assertEqual(self.subject.supported_features, SUPPORT_MODES)
  85. def test_icons(self):
  86. self.dps[SWITCH_DPS] = True
  87. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  88. self.dps[SWITCH_DPS] = False
  89. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  90. def test_min_target_humidity(self):
  91. self.assertEqual(self.subject.min_humidity, 30)
  92. def test_max_target_humidity(self):
  93. self.assertEqual(self.subject.max_humidity, 80)
  94. def test_target_humidity(self):
  95. self.dps[HUMIDITY_DPS] = 55
  96. self.assertEqual(self.subject.target_humidity, 55)
  97. def test_available_modes(self):
  98. self.assertCountEqual(
  99. self.subject.available_modes,
  100. [MODE_AUTO, MODE_BOOST, MODE_NORMAL, MODE_SLEEP],
  101. )
  102. def test_mode(self):
  103. self.dps[PRESET_DPS] = "AUTO"
  104. self.assertEqual(self.subject.mode, MODE_AUTO)
  105. self.dps[PRESET_DPS] = "MIDDLE"
  106. self.assertEqual(self.subject.mode, MODE_NORMAL)
  107. self.dps[PRESET_DPS] = "HIGH"
  108. self.assertEqual(self.subject.mode, MODE_BOOST)
  109. self.dps[PRESET_DPS] = "SLEEP"
  110. self.assertEqual(self.subject.mode, MODE_SLEEP)
  111. async def test_set_mode_to_auto(self):
  112. async with assert_device_properties_set(
  113. self.subject._device, {PRESET_DPS: "AUTO"}
  114. ):
  115. await self.subject.async_set_mode(MODE_AUTO)
  116. async def test_set_mode_to_normal(self):
  117. async with assert_device_properties_set(
  118. self.subject._device, {PRESET_DPS: "MIDDLE"}
  119. ):
  120. await self.subject.async_set_mode(MODE_NORMAL)
  121. async def test_set_mode_to_boost(self):
  122. async with assert_device_properties_set(
  123. self.subject._device, {PRESET_DPS: "HIGH"}
  124. ):
  125. await self.subject.async_set_mode(MODE_BOOST)
  126. async def test_set_mode_to_sleep(self):
  127. async with assert_device_properties_set(
  128. self.subject._device, {PRESET_DPS: "SLEEP"}
  129. ):
  130. await self.subject.async_set_mode(MODE_SLEEP)
  131. def test_extra_state_attributes(self):
  132. self.dps[UNKNOWN22_DPS] = 22
  133. self.assertDictEqual(
  134. self.subject.extra_state_attributes,
  135. {"unknown_22": 22},
  136. )