test_renpho_rp_ap001s.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. from homeassistant.components.fan import SUPPORT_PRESET_MODE
  2. from homeassistant.const import DEVICE_CLASS_AQI
  3. from ..const import RENPHO_PURIFIER_PAYLOAD
  4. from ..helpers import assert_device_properties_set
  5. from ..mixins.light import BasicLightTests
  6. from ..mixins.lock import BasicLockTests
  7. from ..mixins.sensor import MultiSensorTests
  8. from ..mixins.switch import BasicSwitchTests, SwitchableTests
  9. from .base_device_tests import TuyaDeviceTestCase
  10. SWITCH_DPS = "1"
  11. PRESET_DPS = "4"
  12. LOCK_DPS = "7"
  13. LIGHT_DPS = "8"
  14. TIMER_DPS = "19"
  15. QUALITY_DPS = "22"
  16. SLEEP_DPS = "101"
  17. PREFILTER_DPS = "102"
  18. CHARCOAL_DPS = "103"
  19. ACTIVATED_DPS = "104"
  20. HEPA_DPS = "105"
  21. class TestRenphoPurifier(
  22. BasicLightTests,
  23. BasicLockTests,
  24. BasicSwitchTests,
  25. MultiSensorTests,
  26. SwitchableTests,
  27. TuyaDeviceTestCase,
  28. ):
  29. __test__ = True
  30. def setUp(self):
  31. self.setUpForConfig("renpho_rp_ap001s.yaml", RENPHO_PURIFIER_PAYLOAD)
  32. self.subject = self.entities.get("fan")
  33. self.setUpSwitchable(SWITCH_DPS, self.subject)
  34. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_aq_indicator"))
  35. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  36. self.setUpBasicSwitch(SLEEP_DPS, self.entities.get("switch_sleep"))
  37. self.setUpMultiSensors(
  38. [
  39. {
  40. "name": "sensor_air_quality",
  41. "dps": QUALITY_DPS,
  42. "device_class": DEVICE_CLASS_AQI,
  43. },
  44. {
  45. "name": "sensor_prefilter_life",
  46. "dps": PREFILTER_DPS,
  47. },
  48. {
  49. "name": "sensor_charcoal_filter_life",
  50. "dps": CHARCOAL_DPS,
  51. },
  52. {
  53. "name": "sensor_active_filter_life",
  54. "dps": ACTIVATED_DPS,
  55. },
  56. {
  57. "name": "sensor_hepa_filter_life",
  58. "dps": HEPA_DPS,
  59. },
  60. ]
  61. )
  62. def test_supported_features(self):
  63. self.assertEqual(self.subject.supported_features, SUPPORT_PRESET_MODE)
  64. def test_preset_modes(self):
  65. self.assertCountEqual(
  66. self.subject.preset_modes,
  67. ["low", "mid", "high", "auto"],
  68. )
  69. def test_preset_mode(self):
  70. self.dps[PRESET_DPS] = "low"
  71. self.assertEqual(self.subject.preset_mode, "low")
  72. self.dps[PRESET_DPS] = "mid"
  73. self.assertEqual(self.subject.preset_mode, "mid")
  74. self.dps[PRESET_DPS] = "high"
  75. self.assertEqual(self.subject.preset_mode, "high")
  76. self.dps[PRESET_DPS] = "auto"
  77. self.assertEqual(self.subject.preset_mode, "auto")
  78. async def test_set_preset_mode_to_low(self):
  79. async with assert_device_properties_set(
  80. self.subject._device,
  81. {PRESET_DPS: "low"},
  82. ):
  83. await self.subject.async_set_preset_mode("low")
  84. async def test_set_preset_mode_to_mid(self):
  85. async with assert_device_properties_set(
  86. self.subject._device,
  87. {PRESET_DPS: "mid"},
  88. ):
  89. await self.subject.async_set_preset_mode("mid")
  90. async def test_set_preset_mode_to_high(self):
  91. async with assert_device_properties_set(
  92. self.subject._device,
  93. {PRESET_DPS: "high"},
  94. ):
  95. await self.subject.async_set_preset_mode("high")
  96. async def test_set_preset_mode_to_auto(self):
  97. async with assert_device_properties_set(
  98. self.subject._device,
  99. {PRESET_DPS: "auto"},
  100. ):
  101. await self.subject.async_set_preset_mode("auto")
  102. def test_device_state_attributes(self):
  103. self.dps[TIMER_DPS] = "19"
  104. self.dps[QUALITY_DPS] = "22"
  105. self.dps[PREFILTER_DPS] = 102
  106. self.dps[CHARCOAL_DPS] = 103
  107. self.dps[ACTIVATED_DPS] = 104
  108. self.dps[HEPA_DPS] = 105
  109. self.assertDictEqual(
  110. self.subject.device_state_attributes,
  111. {
  112. "timer": "19",
  113. "air_quality": "22",
  114. "prefilter_life": 102,
  115. "charcoal_filter_life": 103,
  116. "activated_charcoal_filter_life": 104,
  117. "hepa_filter_life": 105,
  118. },
  119. )
  120. self.assertEqual(self.basicSwitch.icon, "mdi:power-sleep")