test_renpho_rp_ap001s.py 4.7 KB

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