test_himox_h06_purifier.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. PERCENTAGE,
  6. UnitOfTime,
  7. )
  8. from ..const import HIMOX_H06_PURIFIER_PAYLOAD
  9. from ..helpers import assert_device_properties_set
  10. from ..mixins.button import BasicButtonTests
  11. from ..mixins.light import BasicLightTests
  12. from ..mixins.select import MultiSelectTests
  13. from ..mixins.sensor import MultiSensorTests
  14. from ..mixins.switch import BasicSwitchTests, SwitchableTests
  15. from .base_device_tests import TuyaDeviceTestCase
  16. SWITCH_DPS = "1"
  17. SPEED_DPS = "4"
  18. FILTER_DPS = "5"
  19. LIGHT_DPS = "8"
  20. RESET_DPS = "11"
  21. TIMER_DPS = "18"
  22. COUNTDOWN_DPS = "19"
  23. AQI_DPS = "22"
  24. MODE_DPS = "101"
  25. class TestHimoxH06Purifier(
  26. BasicButtonTests,
  27. BasicLightTests,
  28. BasicSwitchTests,
  29. MultiSelectTests,
  30. MultiSensorTests,
  31. SwitchableTests,
  32. TuyaDeviceTestCase,
  33. ):
  34. __test__ = True
  35. def setUp(self):
  36. self.setUpForConfig("himox_h06_purifier.yaml", HIMOX_H06_PURIFIER_PAYLOAD)
  37. self.subject = self.entities["fan"]
  38. self.setUpSwitchable(SWITCH_DPS, self.subject)
  39. self.setUpBasicButton(
  40. RESET_DPS,
  41. self.entities.get("button_filter_reset"),
  42. ButtonDeviceClass.RESTART,
  43. )
  44. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_aq_indicator"))
  45. self.setUpMultiSelect(
  46. [
  47. {
  48. "dps": TIMER_DPS,
  49. "name": "select_timer",
  50. "options": {
  51. "cancel": "Off",
  52. "4h": "4 hours",
  53. "8h": "8 hours",
  54. },
  55. },
  56. {
  57. "dps": MODE_DPS,
  58. "name": "select_configuration",
  59. "options": {
  60. "calcle": "Auto",
  61. "1": "Medium",
  62. "2": "Severe",
  63. },
  64. },
  65. ]
  66. )
  67. self.setUpBasicSwitch(RESET_DPS, self.entities.get("switch_filter_reset"))
  68. self.setUpMultiSensors(
  69. [
  70. {
  71. "dps": FILTER_DPS,
  72. "name": "sensor_active_filter_life",
  73. "unit": PERCENTAGE,
  74. },
  75. {
  76. "dps": COUNTDOWN_DPS,
  77. "name": "sensor_timer",
  78. "unit": UnitOfTime.MINUTES,
  79. "device_class": SensorDeviceClass.DURATION,
  80. },
  81. {
  82. "dps": AQI_DPS,
  83. "name": "sensor_air_quality",
  84. },
  85. ]
  86. )
  87. self.mark_secondary(
  88. [
  89. "button_filter_reset",
  90. "light_aq_indicator",
  91. "switch_filter_reset",
  92. "sensor_active_filter_life",
  93. "select_timer",
  94. "sensor_timer",
  95. ]
  96. )
  97. def test_supported_features(self):
  98. self.assertEqual(
  99. self.subject.supported_features,
  100. FanEntityFeature.SET_SPEED,
  101. )
  102. def test_speed(self):
  103. self.dps[SPEED_DPS] = "low"
  104. self.assertEqual(self.subject.percentage, 33)
  105. def test_speed_step(self):
  106. self.assertAlmostEqual(self.subject.percentage_step, 33, 0)
  107. async def test_set_speed(self):
  108. async with assert_device_properties_set(
  109. self.subject._device, {SPEED_DPS: "mid"}
  110. ):
  111. await self.subject.async_set_percentage(67)
  112. async def test_set_speed_snaps(self):
  113. async with assert_device_properties_set(
  114. self.subject._device, {SPEED_DPS: "high"}
  115. ):
  116. await self.subject.async_set_percentage(90)