test_electriq_cd12_dehumidifier.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. from homeassistant.components.humidifier import SUPPORT_MODES
  2. from homeassistant.components.light import COLOR_MODE_ONOFF
  3. from homeassistant.const import STATE_UNAVAILABLE
  4. from ..const import ELECTRIQ_CD12PW_DEHUMIDIFIER_PAYLOAD
  5. from ..helpers import assert_device_properties_set
  6. from .base_device_tests import TuyaDeviceTestCase
  7. SWITCH_DPS = "1"
  8. MODE_DPS = "2"
  9. CURRENTHUMID_DPS = "3"
  10. HUMIDITY_DPS = "4"
  11. LIGHT_DPS = "101"
  12. CURRENTTEMP_DPS = "103"
  13. class TestElectriqCD20ProDehumidifier(TuyaDeviceTestCase):
  14. __test__ = True
  15. def setUp(self):
  16. self.setUpForConfig(
  17. "electriq_cd12pw_dehumidifier.yaml", ELECTRIQ_CD12PW_DEHUMIDIFIER_PAYLOAD
  18. )
  19. self.subject = self.entities.get("humidifier")
  20. self.light = self.entities.get("light_display")
  21. def test_supported_features(self):
  22. self.assertEqual(self.subject.supported_features, SUPPORT_MODES)
  23. def test_icon(self):
  24. """Test that the icon is as expected."""
  25. self.dps[SWITCH_DPS] = True
  26. self.dps[MODE_DPS] = "auto"
  27. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  28. self.dps[SWITCH_DPS] = False
  29. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  30. self.dps[MODE_DPS] = "fan"
  31. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  32. self.dps[SWITCH_DPS] = True
  33. self.assertEqual(self.subject.icon, "mdi:air-purifier")
  34. self.dps[LIGHT_DPS] = True
  35. self.assertEqual(self.light.icon, "mdi:led-on")
  36. self.dps[LIGHT_DPS] = False
  37. self.assertEqual(self.light.icon, "mdi:led-off")
  38. def test_min_target_humidity(self):
  39. self.assertEqual(self.subject.min_humidity, 35)
  40. def test_max_target_humidity(self):
  41. self.assertEqual(self.subject.max_humidity, 80)
  42. def test_target_humidity(self):
  43. self.dps[HUMIDITY_DPS] = 55
  44. self.assertEqual(self.subject.target_humidity, 55)
  45. async def test_set_target_humidity_rounds_up_to_5_percent(self):
  46. async with assert_device_properties_set(
  47. self.subject._device,
  48. {HUMIDITY_DPS: 55},
  49. ):
  50. await self.subject.async_set_humidity(53)
  51. async def test_set_target_humidity_rounds_down_to_5_percent(self):
  52. async with assert_device_properties_set(
  53. self.subject._device,
  54. {HUMIDITY_DPS: 50},
  55. ):
  56. await self.subject.async_set_humidity(52)
  57. def test_is_on(self):
  58. self.dps[SWITCH_DPS] = True
  59. self.assertTrue(self.subject.is_on)
  60. self.dps[SWITCH_DPS] = False
  61. self.assertFalse(self.subject.is_on)
  62. self.dps[SWITCH_DPS] = None
  63. self.assertEqual(self.subject.is_on, STATE_UNAVAILABLE)
  64. async def test_turn_on(self):
  65. async with assert_device_properties_set(
  66. self.subject._device, {SWITCH_DPS: True}
  67. ):
  68. await self.subject.async_turn_on()
  69. async def test_turn_off(self):
  70. async with assert_device_properties_set(
  71. self.subject._device, {SWITCH_DPS: False}
  72. ):
  73. await self.subject.async_turn_off()
  74. def test_mode(self):
  75. self.dps[MODE_DPS] = "auto"
  76. self.assertEqual(self.subject.mode, "Auto")
  77. self.dps[MODE_DPS] = "fan"
  78. self.assertEqual(self.subject.mode, "Air clean")
  79. async def test_set_mode_to_auto(self):
  80. async with assert_device_properties_set(
  81. self.subject._device,
  82. {
  83. MODE_DPS: "auto",
  84. },
  85. ):
  86. await self.subject.async_set_mode("Auto")
  87. self.subject._device.anticipate_property_value.assert_not_called()
  88. async def test_set_mode_to_fan(self):
  89. async with assert_device_properties_set(
  90. self.subject._device,
  91. {
  92. MODE_DPS: "fan",
  93. },
  94. ):
  95. await self.subject.async_set_mode("Air clean")
  96. self.subject._device.anticipate_property_value.assert_not_called()
  97. def test_light_supported_color_modes(self):
  98. self.assertCountEqual(
  99. self.light.supported_color_modes,
  100. [COLOR_MODE_ONOFF],
  101. )
  102. def test_light_color_mode(self):
  103. self.assertEqual(self.light.color_mode, COLOR_MODE_ONOFF)
  104. def test_light_is_on(self):
  105. self.dps[LIGHT_DPS] = True
  106. self.assertTrue(self.light.is_on)
  107. self.dps[LIGHT_DPS] = False
  108. self.assertFalse(self.light.is_on)
  109. async def test_light_turn_on(self):
  110. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: True}):
  111. await self.light.async_turn_on()
  112. async def test_light_turn_off(self):
  113. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: False}):
  114. await self.light.async_turn_off()
  115. async def test_toggle_turns_the_light_on_when_it_was_off(self):
  116. self.dps[LIGHT_DPS] = False
  117. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: True}):
  118. await self.light.async_toggle()
  119. async def test_toggle_turns_the_light_off_when_it_was_on(self):
  120. self.dps[LIGHT_DPS] = True
  121. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: False}):
  122. await self.light.async_toggle()
  123. def test_state_attributes(self):
  124. self.dps[CURRENTHUMID_DPS] = 50
  125. self.dps[CURRENTTEMP_DPS] = 21
  126. self.assertDictEqual(
  127. self.subject.device_state_attributes,
  128. {"current_humidity": 50, "current_temperature": 21},
  129. )
  130. self.assertEqual(self.light.device_state_attributes, {})