test_hyundai_sahara_dehumidifier.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.fan import FanEntityFeature
  3. from homeassistant.components.humidifier import HumidifierEntityFeature
  4. from homeassistant.components.sensor import SensorDeviceClass
  5. from homeassistant.const import PERCENTAGE, UnitOfTemperature
  6. from ..const import HYUNDAI_SAHARA_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from ..mixins.binary_sensor import BasicBinarySensorTests
  9. from ..mixins.lock import BasicLockTests
  10. from ..mixins.sensor import MultiSensorTests
  11. from ..mixins.switch import SwitchableTests
  12. from .base_device_tests import TuyaDeviceTestCase
  13. SWITCH_DPS = "1"
  14. HUMIDITY_DPS = "2"
  15. FAN_DPS = "4"
  16. CURRENTHUMID_DPS = "6"
  17. CURRENTTEMP_DPS = "7"
  18. MODE_DPS = "14"
  19. LOCK_DPS = "16"
  20. ERROR_DPS = "19"
  21. class TestHyundaiSaharaDehumidifier(
  22. BasicBinarySensorTests,
  23. BasicLockTests,
  24. MultiSensorTests,
  25. SwitchableTests,
  26. TuyaDeviceTestCase,
  27. ):
  28. __test__ = True
  29. def setUp(self):
  30. self.setUpForConfig("hyundai_sahara_dehumidifier.yaml", HYUNDAI_SAHARA_PAYLOAD)
  31. self.subject = self.entities.get("humidifier")
  32. self.setUpSwitchable(SWITCH_DPS, self.subject)
  33. self.fan = self.entities.get("fan")
  34. self.setUpBasicLock(
  35. LOCK_DPS,
  36. self.entities.get("lock_child_lock"),
  37. )
  38. self.setUpBasicBinarySensor(
  39. ERROR_DPS,
  40. self.entities.get("binary_sensor_tank"),
  41. device_class=BinarySensorDeviceClass.PROBLEM,
  42. testdata=(1, 0),
  43. )
  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": CURRENTTEMP_DPS,
  55. "name": "sensor_current_temperature",
  56. "device_class": SensorDeviceClass.TEMPERATURE,
  57. "state_class": "measurement",
  58. "unit": UnitOfTemperature.CELSIUS,
  59. },
  60. ]
  61. )
  62. self.mark_secondary(["binary_sensor_tank", "lock_child_lock"])
  63. def test_supported_features(self):
  64. self.assertEqual(
  65. self.subject.supported_features,
  66. HumidifierEntityFeature.MODES,
  67. )
  68. self.assertEqual(
  69. self.fan.supported_features,
  70. FanEntityFeature.SET_SPEED,
  71. )
  72. def test_icon(self):
  73. """Test that the icon is as expected."""
  74. self.dps[SWITCH_DPS] = True
  75. self.dps[MODE_DPS] = False
  76. self.dps[ERROR_DPS] = 0
  77. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  78. self.dps[SWITCH_DPS] = False
  79. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  80. self.dps[MODE_DPS] = True
  81. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  82. self.dps[SWITCH_DPS] = True
  83. self.assertEqual(self.subject.icon, "mdi:power-sleep")
  84. self.dps[ERROR_DPS] = 1
  85. self.assertEqual(self.subject.icon, "mdi:cup-water")
  86. def test_min_target_humidity(self):
  87. self.assertEqual(self.subject.min_humidity, 30)
  88. def test_max_target_humidity(self):
  89. self.assertEqual(self.subject.max_humidity, 80)
  90. def test_target_humidity(self):
  91. self.dps[HUMIDITY_DPS] = 55
  92. self.assertEqual(self.subject.target_humidity, 55)
  93. async def test_fan_turn_on(self):
  94. async with assert_device_properties_set(
  95. self.subject._device, {SWITCH_DPS: True}
  96. ):
  97. await self.fan.async_turn_on()
  98. async def test_fan_turn_off(self):
  99. async with assert_device_properties_set(
  100. self.subject._device, {SWITCH_DPS: False}
  101. ):
  102. await self.fan.async_turn_off()
  103. def test_modes(self):
  104. self.assertCountEqual(
  105. self.subject.available_modes,
  106. [
  107. "Normal",
  108. "Sleep",
  109. ],
  110. )
  111. def test_mode(self):
  112. self.dps[MODE_DPS] = False
  113. self.assertEqual(self.subject.mode, "Normal")
  114. self.dps[MODE_DPS] = True
  115. self.assertEqual(self.subject.mode, "Sleep")
  116. async def test_set_mode_to_normal(self):
  117. async with assert_device_properties_set(
  118. self.subject._device,
  119. {
  120. MODE_DPS: False,
  121. },
  122. ):
  123. await self.subject.async_set_mode("Normal")
  124. self.subject._device.anticipate_property_value.assert_not_called()
  125. async def test_set_mode_to_sleep(self):
  126. async with assert_device_properties_set(
  127. self.subject._device,
  128. {
  129. MODE_DPS: True,
  130. },
  131. ):
  132. await self.subject.async_set_mode("Sleep")
  133. self.subject._device.anticipate_property_value.assert_not_called()
  134. def test_fan_speed_steps(self):
  135. self.assertEqual(self.fan.speed_count, 2)
  136. def test_fan_speed(self):
  137. self.dps[FAN_DPS] = "low"
  138. self.assertEqual(self.fan.percentage, 50)
  139. self.dps[FAN_DPS] = "high"
  140. self.assertEqual(self.fan.percentage, 100)
  141. async def test_fan_set_speed_to_low(self):
  142. async with assert_device_properties_set(
  143. self.subject._device,
  144. {
  145. FAN_DPS: "low",
  146. },
  147. ):
  148. await self.fan.async_set_percentage(50)
  149. async def test_fan_set_speed_to_high(self):
  150. async with assert_device_properties_set(
  151. self.subject._device,
  152. {
  153. FAN_DPS: "high",
  154. },
  155. ):
  156. await self.fan.async_set_percentage(100)