test_wetair_wawh1210lw_humidifier.py 4.9 KB

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