test_himox_h06_purifier.py 3.5 KB

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