test_renpho_rp_ap001s.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. from homeassistant.components.fan import FanEntityFeature
  2. from homeassistant.components.sensor import SensorDeviceClass
  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": SensorDeviceClass.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. self.mark_secondary(
  63. [
  64. "light_aq_indicator",
  65. "lock_child_lock",
  66. "sensor_air_quality",
  67. "sensor_active_filter_life",
  68. "sensor_charcoal_filter_life",
  69. "sensor_hepa_filter_life",
  70. "sensor_prefilter_life",
  71. ]
  72. )
  73. def test_supported_features(self):
  74. self.assertEqual(self.subject.supported_features, FanEntityFeature.PRESET_MODE)
  75. def test_preset_modes(self):
  76. self.assertCountEqual(
  77. self.subject.preset_modes,
  78. ["low", "mid", "high", "auto"],
  79. )
  80. def test_preset_mode(self):
  81. self.dps[PRESET_DPS] = "low"
  82. self.assertEqual(self.subject.preset_mode, "low")
  83. self.dps[PRESET_DPS] = "mid"
  84. self.assertEqual(self.subject.preset_mode, "mid")
  85. self.dps[PRESET_DPS] = "high"
  86. self.assertEqual(self.subject.preset_mode, "high")
  87. self.dps[PRESET_DPS] = "auto"
  88. self.assertEqual(self.subject.preset_mode, "auto")
  89. async def test_set_preset_mode_to_low(self):
  90. async with assert_device_properties_set(
  91. self.subject._device,
  92. {PRESET_DPS: "low"},
  93. ):
  94. await self.subject.async_set_preset_mode("low")
  95. async def test_set_preset_mode_to_mid(self):
  96. async with assert_device_properties_set(
  97. self.subject._device,
  98. {PRESET_DPS: "mid"},
  99. ):
  100. await self.subject.async_set_preset_mode("mid")
  101. async def test_set_preset_mode_to_high(self):
  102. async with assert_device_properties_set(
  103. self.subject._device,
  104. {PRESET_DPS: "high"},
  105. ):
  106. await self.subject.async_set_preset_mode("high")
  107. async def test_set_preset_mode_to_auto(self):
  108. async with assert_device_properties_set(
  109. self.subject._device,
  110. {PRESET_DPS: "auto"},
  111. ):
  112. await self.subject.async_set_preset_mode("auto")
  113. def test_extra_state_attributes(self):
  114. self.dps[TIMER_DPS] = "19"
  115. self.dps[QUALITY_DPS] = "22"
  116. self.dps[PREFILTER_DPS] = 102
  117. self.dps[CHARCOAL_DPS] = 103
  118. self.dps[ACTIVATED_DPS] = 104
  119. self.dps[HEPA_DPS] = 105
  120. self.assertDictEqual(
  121. self.subject.extra_state_attributes,
  122. {
  123. "timer": "19",
  124. "air_quality": "22",
  125. "prefilter_life": 102,
  126. "charcoal_filter_life": 103,
  127. "activated_charcoal_filter_life": 104,
  128. "hepa_filter_life": 105,
  129. },
  130. )
  131. def test_icons(self):
  132. self.assertEqual(self.basicSwitch.icon, "mdi:power-sleep")