test_poiema_one_purifier.py 4.6 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 (
  5. CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
  6. UnitOfTime,
  7. )
  8. from ..const import POIEMA_ONE_PURIFIER_PAYLOAD
  9. from ..helpers import assert_device_properties_set
  10. from ..mixins.button import BasicButtonTests
  11. from ..mixins.lock import BasicLockTests
  12. from ..mixins.select import BasicSelectTests
  13. from ..mixins.sensor import MultiSensorTests
  14. from ..mixins.switch import SwitchableTests
  15. from .base_device_tests import TuyaDeviceTestCase
  16. SWITCH_DPS = "1"
  17. PM25_DPS = "2"
  18. MODE_DPS = "3"
  19. SPEED_DPS = "4"
  20. LOCK_DPS = "7"
  21. RESET_DPS = "11"
  22. TIMER_DPS = "18"
  23. COUNTDOWN_DPS = "19"
  24. class TestPoeimaOnePurifier(
  25. BasicButtonTests,
  26. BasicLockTests,
  27. BasicSelectTests,
  28. MultiSensorTests,
  29. SwitchableTests,
  30. TuyaDeviceTestCase,
  31. ):
  32. __test__ = True
  33. def setUp(self):
  34. self.setUpForConfig("poiema_one_purifier.yaml", POIEMA_ONE_PURIFIER_PAYLOAD)
  35. self.subject = self.entities["fan"]
  36. self.setUpSwitchable(SWITCH_DPS, self.subject)
  37. self.setUpBasicButton(
  38. RESET_DPS,
  39. self.entities.get("button_filter_reset"),
  40. ButtonDeviceClass.RESTART,
  41. )
  42. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  43. self.setUpBasicSelect(
  44. TIMER_DPS,
  45. self.entities.get("select_timer"),
  46. {
  47. "cancel": "off",
  48. "1h": "1 hour",
  49. "2h": "2 hours",
  50. "3h": "3 hours",
  51. "4h": "4 hours",
  52. "5h": "5 hours",
  53. },
  54. )
  55. self.setUpMultiSensors(
  56. [
  57. {
  58. "dps": PM25_DPS,
  59. "name": "sensor_pm2_5",
  60. "device_class": SensorDeviceClass.PM25,
  61. "state_class": "measurement",
  62. "unit": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
  63. },
  64. {
  65. "dps": COUNTDOWN_DPS,
  66. "name": "sensor_timer",
  67. "unit": UnitOfTime.MINUTES,
  68. "device_class": SensorDeviceClass.DURATION,
  69. },
  70. ]
  71. )
  72. self.mark_secondary(
  73. [
  74. "button_filter_reset",
  75. "lock_child_lock",
  76. "select_timer",
  77. "sensor_timer",
  78. ]
  79. )
  80. def test_supported_features(self):
  81. self.assertEqual(
  82. self.subject.supported_features,
  83. FanEntityFeature.PRESET_MODE | FanEntityFeature.SET_SPEED,
  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. ["Manual", "Auto", "Sleep"],
  104. )
  105. def test_preset_mode(self):
  106. self.dps[MODE_DPS] = "manual"
  107. self.assertEqual(self.subject.preset_mode, "Manual")
  108. self.dps[MODE_DPS] = "auto"
  109. self.assertEqual(self.subject.preset_mode, "Auto")
  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("Manual")
  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("Auto")
  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")