test_wetair_wawh1210lw_humidifier.py 4.9 KB

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