test_poiema_one_purifier.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. __test__ = True
  29. def setUp(self):
  30. self.setUpForConfig("poiema_one_purifier.yaml", POIEMA_ONE_PURIFIER_PAYLOAD)
  31. self.subject = self.entities["fan"]
  32. self.setUpSwitchable(SWITCH_DPS, self.subject)
  33. self.setUpBasicButton(
  34. RESET_DPS,
  35. self.entities.get("button_filter_reset"),
  36. )
  37. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  38. self.setUpBasicSelect(
  39. TIMER_DPS,
  40. self.entities.get("select_timer"),
  41. {
  42. "cancel": "cancel",
  43. "1h": "1h",
  44. "2h": "2h",
  45. "3h": "3h",
  46. "4h": "4h",
  47. "5h": "5h",
  48. },
  49. )
  50. self.setUpMultiSensors(
  51. [
  52. {
  53. "dps": PM25_DPS,
  54. "name": "sensor_pm25",
  55. "device_class": SensorDeviceClass.PM25,
  56. "state_class": "measurement",
  57. "unit": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
  58. },
  59. {
  60. "dps": COUNTDOWN_DPS,
  61. "name": "sensor_time_remaining",
  62. "unit": UnitOfTime.MINUTES,
  63. "device_class": SensorDeviceClass.DURATION,
  64. },
  65. ]
  66. )
  67. self.mark_secondary(
  68. [
  69. "button_filter_reset",
  70. "lock_child_lock",
  71. "select_timer",
  72. "sensor_time_remaining",
  73. ]
  74. )
  75. def test_supported_features(self):
  76. self.assertEqual(
  77. self.subject.supported_features,
  78. FanEntityFeature.PRESET_MODE
  79. | FanEntityFeature.SET_SPEED
  80. | FanEntityFeature.TURN_OFF
  81. | FanEntityFeature.TURN_ON,
  82. )
  83. def test_speed(self):
  84. self.dps[SPEED_DPS] = "low"
  85. self.assertEqual(self.subject.percentage, 25)
  86. def test_speed_step(self):
  87. self.assertEqual(self.subject.percentage_step, 25)
  88. async def test_set_speed(self):
  89. async with assert_device_properties_set(
  90. self.subject._device, {SPEED_DPS: "mid"}
  91. ):
  92. await self.subject.async_set_percentage(50)
  93. async def test_set_speed_snaps(self):
  94. async with assert_device_properties_set(
  95. self.subject._device, {SPEED_DPS: "high"}
  96. ):
  97. await self.subject.async_set_percentage(70)
  98. def test_preset_modes(self):
  99. self.assertCountEqual(
  100. self.subject.preset_modes,
  101. ["normal", "smart", "sleep"],
  102. )
  103. def test_preset_mode(self):
  104. self.dps[MODE_DPS] = "manual"
  105. self.assertEqual(self.subject.preset_mode, "normal")
  106. self.dps[MODE_DPS] = "auto"
  107. self.assertEqual(self.subject.preset_mode, "smart")
  108. self.dps[MODE_DPS] = "sleep"
  109. self.assertEqual(self.subject.preset_mode, "sleep")
  110. async def test_set_preset_to_manual(self):
  111. async with assert_device_properties_set(
  112. self.subject._device,
  113. {MODE_DPS: "manual"},
  114. ):
  115. await self.subject.async_set_preset_mode("normal")
  116. async def test_set_preset_to_auto(self):
  117. async with assert_device_properties_set(
  118. self.subject._device,
  119. {MODE_DPS: "auto"},
  120. ):
  121. await self.subject.async_set_preset_mode("smart")
  122. async def test_set_preset_to_sleep(self):
  123. async with assert_device_properties_set(
  124. self.subject._device,
  125. {MODE_DPS: "sleep"},
  126. ):
  127. await self.subject.async_set_preset_mode("sleep")