test_renpho_rp_ap001s.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. 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(
  37. SLEEP_DPS,
  38. self.entities.get("switch_sleep"),
  39. device_class=SwitchDeviceClass.SWITCH,
  40. )
  41. self.setUpMultiSensors(
  42. [
  43. {
  44. "name": "sensor_air_quality",
  45. "dps": QUALITY_DPS,
  46. "device_class": SensorDeviceClass.ENUM,
  47. "options": ["poor", "moderate", "good"],
  48. },
  49. {
  50. "name": "sensor_prefilter_life",
  51. "dps": PREFILTER_DPS,
  52. },
  53. {
  54. "name": "sensor_charcoal_filter_life",
  55. "dps": CHARCOAL_DPS,
  56. },
  57. {
  58. "name": "sensor_active_filter_life",
  59. "dps": ACTIVATED_DPS,
  60. },
  61. {
  62. "name": "sensor_hepa_filter_life",
  63. "dps": HEPA_DPS,
  64. },
  65. ]
  66. )
  67. self.mark_secondary(
  68. [
  69. "light_aq_indicator",
  70. "lock_child_lock",
  71. "sensor_air_quality",
  72. "sensor_active_filter_life",
  73. "sensor_charcoal_filter_life",
  74. "sensor_hepa_filter_life",
  75. "sensor_prefilter_life",
  76. ]
  77. )
  78. def test_supported_features(self):
  79. self.assertEqual(
  80. self.subject.supported_features,
  81. FanEntityFeature.PRESET_MODE
  82. | FanEntityFeature.TURN_OFF
  83. | FanEntityFeature.TURN_ON,
  84. )
  85. def test_preset_modes(self):
  86. self.assertCountEqual(
  87. self.subject.preset_modes,
  88. ["sleep", "fresh", "strong", "smart"],
  89. )
  90. def test_preset_mode(self):
  91. self.dps[PRESET_DPS] = "low"
  92. self.assertEqual(self.subject.preset_mode, "sleep")
  93. self.dps[PRESET_DPS] = "mid"
  94. self.assertEqual(self.subject.preset_mode, "fresh")
  95. self.dps[PRESET_DPS] = "high"
  96. self.assertEqual(self.subject.preset_mode, "strong")
  97. self.dps[PRESET_DPS] = "auto"
  98. self.assertEqual(self.subject.preset_mode, "smart")
  99. async def test_set_preset_mode_to_low(self):
  100. async with assert_device_properties_set(
  101. self.subject._device,
  102. {PRESET_DPS: "low"},
  103. ):
  104. await self.subject.async_set_preset_mode("sleep")
  105. async def test_set_preset_mode_to_mid(self):
  106. async with assert_device_properties_set(
  107. self.subject._device,
  108. {PRESET_DPS: "mid"},
  109. ):
  110. await self.subject.async_set_preset_mode("fresh")
  111. async def test_set_preset_mode_to_high(self):
  112. async with assert_device_properties_set(
  113. self.subject._device,
  114. {PRESET_DPS: "high"},
  115. ):
  116. await self.subject.async_set_preset_mode("strong")
  117. async def test_set_preset_mode_to_auto(self):
  118. async with assert_device_properties_set(
  119. self.subject._device,
  120. {PRESET_DPS: "auto"},
  121. ):
  122. await self.subject.async_set_preset_mode("smart")
  123. def test_extra_state_attributes(self):
  124. self.dps[TIMER_DPS] = "19"
  125. self.assertDictEqual(
  126. self.subject.extra_state_attributes,
  127. {
  128. "timer": "19",
  129. },
  130. )