test_himox_h05_purifier.py 3.3 KB

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