test_himox_h05_purifier.py 3.5 KB

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