test_poiema_one_purifier.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. from homeassistant.components.fan import FanEntityFeature
  2. from homeassistant.components.sensor import SensorDeviceClass
  3. from homeassistant.const import CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, UnitOfTime
  4. from ..const import POIEMA_ONE_PURIFIER_PAYLOAD
  5. from ..helpers import assert_device_properties_set
  6. from ..mixins.button import BasicButtonTests
  7. from ..mixins.lock import BasicLockTests
  8. from ..mixins.select import BasicSelectTests
  9. from ..mixins.sensor import MultiSensorTests
  10. from ..mixins.switch import SwitchableTests
  11. from .base_device_tests import TuyaDeviceTestCase
  12. SWITCH_DPS = "1"
  13. PM25_DPS = "2"
  14. MODE_DPS = "3"
  15. SPEED_DPS = "4"
  16. LOCK_DPS = "7"
  17. RESET_DPS = "11"
  18. TIMER_DPS = "18"
  19. COUNTDOWN_DPS = "19"
  20. class TestPoeimaOnePurifier(
  21. BasicButtonTests,
  22. BasicLockTests,
  23. BasicSelectTests,
  24. MultiSensorTests,
  25. SwitchableTests,
  26. TuyaDeviceTestCase,
  27. ):
  28. def setUp(self):
  29. self.setUpForConfig("poiema_one_purifier.yaml", POIEMA_ONE_PURIFIER_PAYLOAD)
  30. self.subject = self.entities["fan"]
  31. self.setUpSwitchable(SWITCH_DPS, self.subject)
  32. self.setUpBasicButton(
  33. RESET_DPS,
  34. self.entities.get("button_filter_reset"),
  35. )
  36. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  37. self.setUpBasicSelect(
  38. TIMER_DPS,
  39. self.entities.get("select_timer"),
  40. {
  41. "cancel": "cancel",
  42. "1h": "1h",
  43. "2h": "2h",
  44. "3h": "3h",
  45. "4h": "4h",
  46. "5h": "5h",
  47. },
  48. )
  49. self.setUpMultiSensors(
  50. [
  51. {
  52. "dps": PM25_DPS,
  53. "name": "sensor_pm25",
  54. "device_class": SensorDeviceClass.PM25,
  55. "state_class": "measurement",
  56. "unit": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
  57. },
  58. {
  59. "dps": COUNTDOWN_DPS,
  60. "name": "sensor_time_remaining",
  61. "unit": UnitOfTime.MINUTES,
  62. "device_class": SensorDeviceClass.DURATION,
  63. },
  64. ]
  65. )
  66. self.mark_secondary(
  67. [
  68. "button_filter_reset",
  69. "lock_child_lock",
  70. "select_timer",
  71. "sensor_time_remaining",
  72. ]
  73. )
  74. def test_supported_features(self):
  75. self.assertEqual(
  76. self.subject.supported_features,
  77. FanEntityFeature.PRESET_MODE
  78. | FanEntityFeature.SET_SPEED
  79. | FanEntityFeature.TURN_OFF
  80. | FanEntityFeature.TURN_ON,
  81. )
  82. def test_speed(self):
  83. self.dps[SPEED_DPS] = "low"
  84. self.assertEqual(self.subject.percentage, 25)
  85. def test_speed_step(self):
  86. self.assertEqual(self.subject.percentage_step, 25)
  87. async def test_set_speed(self):
  88. async with assert_device_properties_set(
  89. self.subject._device, {SPEED_DPS: "mid"}
  90. ):
  91. await self.subject.async_set_percentage(50)
  92. async def test_set_speed_snaps(self):
  93. async with assert_device_properties_set(
  94. self.subject._device, {SPEED_DPS: "high"}
  95. ):
  96. await self.subject.async_set_percentage(70)
  97. def test_preset_modes(self):
  98. self.assertCountEqual(
  99. self.subject.preset_modes,
  100. ["normal", "smart", "sleep"],
  101. )
  102. def test_preset_mode(self):
  103. self.dps[MODE_DPS] = "manual"
  104. self.assertEqual(self.subject.preset_mode, "normal")
  105. self.dps[MODE_DPS] = "auto"
  106. self.assertEqual(self.subject.preset_mode, "smart")
  107. self.dps[MODE_DPS] = "sleep"
  108. self.assertEqual(self.subject.preset_mode, "sleep")
  109. async def test_set_preset_to_manual(self):
  110. async with assert_device_properties_set(
  111. self.subject._device,
  112. {MODE_DPS: "manual"},
  113. ):
  114. await self.subject.async_set_preset_mode("normal")
  115. async def test_set_preset_to_auto(self):
  116. async with assert_device_properties_set(
  117. self.subject._device,
  118. {MODE_DPS: "auto"},
  119. ):
  120. await self.subject.async_set_preset_mode("smart")
  121. async def test_set_preset_to_sleep(self):
  122. async with assert_device_properties_set(
  123. self.subject._device,
  124. {MODE_DPS: "sleep"},
  125. ):
  126. await self.subject.async_set_preset_mode("sleep")