test_himox_h05_purifier.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. def setUp(self):
  29. self.setUpForConfig("himox_h05_purifier.yaml", HIMOX_H05_PURIFIER_PAYLOAD)
  30. self.subject = self.entities["fan"]
  31. self.setUpSwitchable(SWITCH_DPS, self.subject)
  32. self.setUpBasicButton(
  33. RESET_DPS,
  34. self.entities.get("button_filter_reset"),
  35. )
  36. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  37. self.setUpBasicSelect(
  38. TIMER_DPS,
  39. self.entities.get("select_timer"),
  40. {
  41. "cancel": "cancel",
  42. "1h": "1h",
  43. "2h": "2h",
  44. "4h": "4h",
  45. "8h": "8h",
  46. },
  47. )
  48. self.setUpMultiSensors(
  49. [
  50. {
  51. "dps": TEMP_DPS,
  52. "name": "sensor_temperature",
  53. "unit": UnitOfTemperature.CELSIUS,
  54. "device_class": SensorDeviceClass.TEMPERATURE,
  55. "state_class": SensorStateClass.MEASUREMENT,
  56. },
  57. {
  58. "dps": FILTER_DPS,
  59. "name": "sensor_active_filter_life",
  60. "unit": PERCENTAGE,
  61. },
  62. {
  63. "dps": AQI_DPS,
  64. "name": "sensor_air_quality",
  65. },
  66. ]
  67. )
  68. self.mark_secondary(
  69. [
  70. "button_filter_reset",
  71. "lock_child_lock",
  72. "sensor_active_filter_life",
  73. "select_timer",
  74. "sensor_temperature",
  75. ]
  76. )
  77. def test_supported_features(self):
  78. self.assertEqual(
  79. self.subject.supported_features,
  80. FanEntityFeature.PRESET_MODE
  81. | FanEntityFeature.TURN_ON
  82. | FanEntityFeature.TURN_OFF,
  83. )
  84. def test_preset_modes(self):
  85. self.assertCountEqual(
  86. self.subject.preset_modes,
  87. ["smart", "sleep", "fresh", "strong"],
  88. )
  89. def test_preset_mode(self):
  90. self.dps[PRESET_DPS] = "low"
  91. self.assertEqual(self.subject.preset_mode, "sleep")
  92. async def test_set_preset_mode(self):
  93. async with assert_device_properties_set(
  94. self.subject._device, {PRESET_DPS: "mid"}
  95. ):
  96. await self.subject.async_set_preset_mode("fresh")