test_poiema_one_purifier.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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": "off",
  45. "1h": "1 hour",
  46. "2h": "2 hours",
  47. "3h": "3 hours",
  48. "4h": "4 hours",
  49. "5h": "5 hours",
  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_timer",
  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_timer",
  75. ]
  76. )
  77. def test_supported_features(self):
  78. self.assertEqual(
  79. self.subject.supported_features,
  80. FanEntityFeature.PRESET_MODE | FanEntityFeature.SET_SPEED,
  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")