test_poiema_one_purifier.py 4.7 KB

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