test_poiema_one_purifier.py 4.4 KB

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