test_electriq_cd12pwv2_dehumidifier.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. from homeassistant.components.humidifier import HumidifierEntityFeature
  2. from homeassistant.components.sensor import SensorDeviceClass
  3. from homeassistant.const import (
  4. PERCENTAGE,
  5. )
  6. from ..const import ELECTRIQ_CD12PWV2_DEHUMIDIFIER_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from ..mixins.binary_sensor import BasicBinarySensorTests
  9. from ..mixins.light import BasicLightTests
  10. from ..mixins.sensor import BasicSensorTests
  11. from ..mixins.switch import BasicSwitchTests, SwitchableTests
  12. from .base_device_tests import TuyaDeviceTestCase
  13. SWITCH_DPS = "1"
  14. HUMIDITY_DPS = "2"
  15. MODE_DPS = "5"
  16. CURRENTHUMID_DPS = "6"
  17. ERROR_DPS = "19"
  18. LIGHT_DPS = "101"
  19. SLEEP_DPS = "104"
  20. class TestElectriqCD12PWV2Dehumidifier(
  21. BasicBinarySensorTests,
  22. BasicLightTests,
  23. BasicSensorTests,
  24. BasicSwitchTests,
  25. SwitchableTests,
  26. TuyaDeviceTestCase,
  27. ):
  28. __test__ = True
  29. def setUp(self):
  30. self.setUpForConfig(
  31. "electriq_cd12pwv2_dehumidifier.yaml",
  32. ELECTRIQ_CD12PWV2_DEHUMIDIFIER_PAYLOAD,
  33. )
  34. self.subject = self.entities.get("humidifier")
  35. self.setUpSwitchable(SWITCH_DPS, self.subject)
  36. self.setUpBasicBinarySensor(
  37. ERROR_DPS, self.entities.get("binary_sensor_tank"), testdata=(1, 0)
  38. )
  39. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_display"))
  40. self.setUpBasicSensor(
  41. CURRENTHUMID_DPS,
  42. self.entities.get("sensor_current_humidity"),
  43. unit=PERCENTAGE,
  44. device_class=SensorDeviceClass.HUMIDITY,
  45. state_class="measurement",
  46. )
  47. self.setUpBasicSwitch(
  48. SLEEP_DPS,
  49. self.entities.get("switch_sleep"),
  50. )
  51. self.mark_secondary(["light_display", "switch_sleep", "binary_sensor_tank"])
  52. def test_supported_features(self):
  53. self.assertEqual(self.subject.supported_features, HumidifierEntityFeature.MODES)
  54. def test_icon(self):
  55. """Test that the icon is as expected."""
  56. self.dps[SWITCH_DPS] = True
  57. self.dps[MODE_DPS] = "Smart"
  58. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  59. self.dps[SWITCH_DPS] = False
  60. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  61. self.dps[MODE_DPS] = "Air_purifier"
  62. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  63. self.dps[SWITCH_DPS] = True
  64. self.assertEqual(self.subject.icon, "mdi:air-purifier")
  65. self.dps[LIGHT_DPS] = True
  66. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  67. self.dps[LIGHT_DPS] = False
  68. self.assertEqual(self.basicLight.icon, "mdi:led-off")
  69. self.dps[SLEEP_DPS] = True
  70. self.assertEqual(self.basicSwitch.icon, "mdi:sleep")
  71. self.dps[SLEEP_DPS] = False
  72. self.assertEqual(self.basicSwitch.icon, "mdi:sleep-off")
  73. def test_min_target_humidity(self):
  74. self.assertEqual(self.subject.min_humidity, 35)
  75. def test_max_target_humidity(self):
  76. self.assertEqual(self.subject.max_humidity, 80)
  77. def test_target_humidity(self):
  78. self.dps[HUMIDITY_DPS] = 55
  79. self.assertEqual(self.subject.target_humidity, 55)
  80. async def test_set_target_humidity_rounds_up_to_5_percent(self):
  81. async with assert_device_properties_set(
  82. self.subject._device,
  83. {HUMIDITY_DPS: 55},
  84. ):
  85. await self.subject.async_set_humidity(53)
  86. async def test_set_target_humidity_rounds_down_to_5_percent(self):
  87. async with assert_device_properties_set(
  88. self.subject._device,
  89. {HUMIDITY_DPS: 50},
  90. ):
  91. await self.subject.async_set_humidity(52)
  92. def test_mode(self):
  93. self.dps[MODE_DPS] = "Smart"
  94. self.assertEqual(self.subject.mode, "Smart")
  95. self.dps[MODE_DPS] = "Air_purifier"
  96. self.assertEqual(self.subject.mode, "Air Purifier")
  97. async def test_set_mode_to_smart(self):
  98. async with assert_device_properties_set(
  99. self.subject._device,
  100. {
  101. MODE_DPS: "Smart",
  102. },
  103. ):
  104. await self.subject.async_set_mode("Smart")
  105. self.subject._device.anticipate_property_value.assert_not_called()
  106. async def test_set_mode_to_air_purify(self):
  107. async with assert_device_properties_set(
  108. self.subject._device,
  109. {
  110. MODE_DPS: "Air_purifier",
  111. },
  112. ):
  113. await self.subject.async_set_mode("Air Purifier")
  114. self.subject._device.anticipate_property_value.assert_not_called()
  115. def test_extra_state_attributes(self):
  116. self.dps[CURRENTHUMID_DPS] = 50
  117. self.dps[ERROR_DPS] = 2
  118. self.assertDictEqual(
  119. self.subject.extra_state_attributes,
  120. {"current_humidity": 50, "error_code": 2},
  121. )