test_himox_h05_purifier.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. from homeassistant.components.button import ButtonDeviceClass
  2. from homeassistant.components.fan import FanEntityFeature
  3. from homeassistant.components.sensor import (
  4. SensorDeviceClass,
  5. STATE_CLASS_MEASUREMENT,
  6. )
  7. from homeassistant.const import (
  8. PERCENTAGE,
  9. TIME_MINUTES,
  10. UnitOfTemperature,
  11. )
  12. from ..const import HIMOX_H05_PURIFIER_PAYLOAD
  13. from ..helpers import assert_device_properties_set
  14. from ..mixins.button import BasicButtonTests
  15. from ..mixins.lock import BasicLockTests
  16. from ..mixins.select import BasicSelectTests
  17. from ..mixins.sensor import MultiSensorTests
  18. from ..mixins.switch import BasicSwitchTests, SwitchableTests
  19. from .base_device_tests import TuyaDeviceTestCase
  20. SWITCH_DPS = "1"
  21. TEMP_DPS = "2"
  22. PRESET_DPS = "4"
  23. FILTER_DPS = "5"
  24. LOCK_DPS = "7"
  25. RESET_DPS = "11"
  26. TIMER_DPS = "18"
  27. AQI_DPS = "21"
  28. class TestHimoxH05Purifier(
  29. BasicButtonTests,
  30. BasicLockTests,
  31. BasicSwitchTests,
  32. BasicSelectTests,
  33. MultiSensorTests,
  34. SwitchableTests,
  35. TuyaDeviceTestCase,
  36. ):
  37. __test__ = True
  38. def setUp(self):
  39. self.setUpForConfig("himox_h05_purifier.yaml", HIMOX_H05_PURIFIER_PAYLOAD)
  40. self.subject = self.entities["fan"]
  41. self.setUpSwitchable(SWITCH_DPS, self.subject)
  42. self.setUpBasicButton(
  43. RESET_DPS,
  44. self.entities.get("button_filter_reset"),
  45. ButtonDeviceClass.RESTART,
  46. )
  47. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  48. self.setUpBasicSelect(
  49. TIMER_DPS,
  50. self.entities.get("select_timer"),
  51. {
  52. "cancel": "Off",
  53. "1h": "1 hour",
  54. "2h": "2 hours",
  55. "4h": "4 hours",
  56. "8h": "8 hours",
  57. },
  58. )
  59. self.setUpBasicSwitch(RESET_DPS, self.entities.get("switch_filter_reset"))
  60. self.setUpMultiSensors(
  61. [
  62. {
  63. "dps": TEMP_DPS,
  64. "name": "sensor_current_temperature",
  65. "unit": UnitOfTemperature.CELSIUS,
  66. "device_class": SensorDeviceClass.TEMPERATURE,
  67. "state_class": STATE_CLASS_MEASUREMENT,
  68. },
  69. {
  70. "dps": FILTER_DPS,
  71. "name": "sensor_active_filter_life",
  72. "unit": PERCENTAGE,
  73. },
  74. {
  75. "dps": AQI_DPS,
  76. "name": "sensor_air_quality",
  77. },
  78. ]
  79. )
  80. self.mark_secondary(
  81. [
  82. "button_filter_reset",
  83. "lock_child_lock",
  84. "switch_filter_reset",
  85. "sensor_active_filter_life",
  86. "select_timer",
  87. "sensor_current_temperature",
  88. ]
  89. )
  90. def test_supported_features(self):
  91. self.assertEqual(
  92. self.subject.supported_features,
  93. FanEntityFeature.PRESET_MODE,
  94. )
  95. def test_preset_modes(self):
  96. self.assertCountEqual(
  97. self.subject.preset_modes,
  98. ["auto", "low", "mid", "high"],
  99. )
  100. def test_preset_mode(self):
  101. self.dps[PRESET_DPS] = "low"
  102. self.assertEqual(self.subject.preset_mode, "low")
  103. async def test_set_preset_mode(self):
  104. async with assert_device_properties_set(
  105. self.subject._device, {PRESET_DPS: "mid"}
  106. ):
  107. await self.subject.async_set_preset_mode("mid")