test_eesee_adam_dehumidifier.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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
  6. from ..const import EESEE_ADAM_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.select import BasicSelectTests
  11. from ..mixins.sensor import BasicSensorTests
  12. from ..mixins.switch import SwitchableTests
  13. from .base_device_tests import TuyaDeviceTestCase
  14. SWITCH_DPS = "1"
  15. HUMIDITY_DPS = "2"
  16. MODE_DPS = "4"
  17. FAN_DPS = "5"
  18. LOCK_DPS = "14"
  19. CURRENTHUMID_DPS = "16"
  20. TIMER_DPS = "17"
  21. ERROR_DPS = "19"
  22. class TestEeseeAdamDehumidifier(
  23. BasicBinarySensorTests,
  24. BasicLockTests,
  25. BasicSelectTests,
  26. BasicSensorTests,
  27. SwitchableTests,
  28. TuyaDeviceTestCase,
  29. ):
  30. __test__ = True
  31. def setUp(self):
  32. self.setUpForConfig("eesee_adam_dehumidifier.yaml", EESEE_ADAM_PAYLOAD)
  33. self.subject = self.entities.get("humidifier")
  34. self.setUpSwitchable(SWITCH_DPS, self.subject)
  35. self.fan = self.entities.get("fan")
  36. self.setUpBasicLock(
  37. LOCK_DPS,
  38. self.entities.get("lock_child_lock"),
  39. )
  40. self.setUpBasicSelect(
  41. TIMER_DPS,
  42. self.entities.get("select_timer"),
  43. {
  44. "cancel": "Off",
  45. "1h": "1 hour",
  46. "2h": "2 hours",
  47. "3h": "3 hours",
  48. "4h": "4 hours",
  49. "5h": "5 hours",
  50. "6h": "6 hours",
  51. "7h": "7 hours",
  52. "8h": "8 hours",
  53. "9h": "9 hours",
  54. "10h": "10 hours",
  55. "11h": "11 hours",
  56. "12h": "12 hours",
  57. "13h": "13 hours",
  58. "14h": "14 hours",
  59. "15h": "15 hours",
  60. "16h": "16 hours",
  61. "17h": "17 hours",
  62. "18h": "18 hours",
  63. "19h": "19 hours",
  64. "20h": "20 hours",
  65. "21h": "21 hours",
  66. "22h": "22 hours",
  67. "23h": "23 hours",
  68. "24h": "24 hours",
  69. },
  70. )
  71. self.setUpBasicBinarySensor(
  72. ERROR_DPS,
  73. self.entities.get("binary_sensor_tank"),
  74. device_class=BinarySensorDeviceClass.PROBLEM,
  75. testdata=(1, 0),
  76. )
  77. self.setUpBasicSensor(
  78. CURRENTHUMID_DPS,
  79. self.entities.get("sensor_current_humidity"),
  80. device_class=SensorDeviceClass.HUMIDITY,
  81. state_class="measurement",
  82. unit=PERCENTAGE,
  83. )
  84. self.mark_secondary(["binary_sensor_tank", "lock_child_lock", "select_timer"])
  85. def test_supported_features(self):
  86. self.assertEqual(
  87. self.subject.supported_features,
  88. HumidifierEntityFeature.MODES,
  89. )
  90. self.assertEqual(
  91. self.fan.supported_features,
  92. FanEntityFeature.SET_SPEED,
  93. )
  94. def test_icon(self):
  95. """Test that the icon is as expected."""
  96. self.dps[SWITCH_DPS] = True
  97. self.dps[MODE_DPS] = "manual"
  98. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  99. self.dps[SWITCH_DPS] = False
  100. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  101. self.dps[MODE_DPS] = "laundry"
  102. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  103. self.dps[SWITCH_DPS] = True
  104. self.assertEqual(self.subject.icon, "mdi:tshirt-crew-outline")
  105. self.dps[ERROR_DPS] = 1
  106. self.assertEqual(self.subject.icon, "mdi:cup-water")
  107. def test_min_target_humidity(self):
  108. self.assertEqual(self.subject.min_humidity, 25)
  109. def test_max_target_humidity(self):
  110. self.assertEqual(self.subject.max_humidity, 80)
  111. def test_target_humidity(self):
  112. self.dps[HUMIDITY_DPS] = 55
  113. self.assertEqual(self.subject.target_humidity, 55)
  114. async def test_fan_turn_on(self):
  115. async with assert_device_properties_set(
  116. self.subject._device, {SWITCH_DPS: True}
  117. ):
  118. await self.fan.async_turn_on()
  119. async def test_fan_turn_off(self):
  120. async with assert_device_properties_set(
  121. self.subject._device, {SWITCH_DPS: False}
  122. ):
  123. await self.fan.async_turn_off()
  124. def test_modes(self):
  125. self.assertCountEqual(
  126. self.subject.available_modes,
  127. [
  128. "Manual",
  129. "Dry clothes",
  130. ],
  131. )
  132. def test_mode(self):
  133. self.dps[MODE_DPS] = "manual"
  134. self.assertEqual(self.subject.mode, "Manual")
  135. self.dps[MODE_DPS] = "laundry"
  136. self.assertEqual(self.subject.mode, "Dry clothes")
  137. async def test_set_mode_to_manual(self):
  138. async with assert_device_properties_set(
  139. self.subject._device,
  140. {
  141. MODE_DPS: "manual",
  142. },
  143. ):
  144. await self.subject.async_set_mode("Manual")
  145. self.subject._device.anticipate_property_value.assert_not_called()
  146. async def test_set_mode_to_clothes(self):
  147. async with assert_device_properties_set(
  148. self.subject._device,
  149. {
  150. MODE_DPS: "laundry",
  151. },
  152. ):
  153. await self.subject.async_set_mode("Dry clothes")
  154. self.subject._device.anticipate_property_value.assert_not_called()
  155. def test_fan_speed_steps(self):
  156. self.assertEqual(self.fan.speed_count, 2)
  157. def test_fan_speed(self):
  158. self.dps[FAN_DPS] = "low"
  159. self.assertEqual(self.fan.percentage, 50)
  160. self.dps[FAN_DPS] = "high"
  161. self.assertEqual(self.fan.percentage, 100)
  162. self.dps[MODE_DPS] = "laundry"
  163. self.assertEqual(self.fan.percentage, 100)
  164. async def test_fan_set_speed_to_low(self):
  165. async with assert_device_properties_set(
  166. self.subject._device,
  167. {
  168. FAN_DPS: "low",
  169. },
  170. ):
  171. await self.fan.async_set_percentage(50)
  172. async def test_fan_set_speed_to_high(self):
  173. async with assert_device_properties_set(
  174. self.subject._device,
  175. {
  176. FAN_DPS: "high",
  177. },
  178. ):
  179. await self.fan.async_set_percentage(100)