test_alecoair_d14_dehumidifier.py 7.6 KB

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