test_vork_vk6067aw_purifier.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.button import ButtonDeviceClass
  3. from homeassistant.components.fan import FanEntityFeature
  4. from homeassistant.components.sensor import SensorDeviceClass
  5. from homeassistant.const import (
  6. PERCENTAGE,
  7. UnitOfTime,
  8. )
  9. from ..const import VORK_VK6067_PURIFIER_PAYLOAD
  10. from ..helpers import assert_device_properties_set
  11. from ..mixins.binary_sensor import BasicBinarySensorTests
  12. from ..mixins.button import BasicButtonTests
  13. from ..mixins.light import BasicLightTests
  14. from ..mixins.select import BasicSelectTests
  15. from ..mixins.sensor import MultiSensorTests
  16. from ..mixins.switch import BasicSwitchTests, SwitchableTests
  17. from .base_device_tests import TuyaDeviceTestCase
  18. SWITCH_DPS = "1"
  19. MODE_DPS = "4"
  20. FILTER_DPS = "5"
  21. LIGHT_DPS = "8"
  22. RESET_DPS = "11"
  23. TIMER_DPS = "18"
  24. COUNTDOWN_DPS = "19"
  25. AQI_DPS = "21"
  26. ERROR_DPS = "22"
  27. class TestVorkVK6267AWPurifier(
  28. BasicBinarySensorTests,
  29. BasicButtonTests,
  30. BasicLightTests,
  31. BasicSelectTests,
  32. BasicSwitchTests,
  33. MultiSensorTests,
  34. SwitchableTests,
  35. TuyaDeviceTestCase,
  36. ):
  37. __test__ = True
  38. def setUp(self):
  39. self.setUpForConfig("vork_vk6067aw_purifier.yaml", VORK_VK6067_PURIFIER_PAYLOAD)
  40. self.subject = self.entities["fan"]
  41. self.setUpSwitchable(SWITCH_DPS, self.subject)
  42. self.setUpBasicBinarySensor(
  43. ERROR_DPS,
  44. self.entities.get("binary_sensor_error"),
  45. device_class=BinarySensorDeviceClass.PROBLEM,
  46. testdata=(1, 0),
  47. )
  48. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light"))
  49. self.setUpBasicSelect(
  50. TIMER_DPS,
  51. self.entities.get("select_timer"),
  52. {
  53. "cancel": "off",
  54. "1h": "1 hour",
  55. "2h": "2 hours",
  56. },
  57. )
  58. self.setUpBasicSwitch(RESET_DPS, self.entities.get("switch_filter_reset"))
  59. self.setUpBasicButton(
  60. RESET_DPS,
  61. self.entities.get("button_filter_reset"),
  62. device_class=ButtonDeviceClass.RESTART,
  63. )
  64. self.setUpMultiSensors(
  65. [
  66. {
  67. "dps": AQI_DPS,
  68. "name": "sensor_air_quality",
  69. "device_class": SensorDeviceClass.ENUM,
  70. "testdata": ("great", "Great"),
  71. "options": ["Great", "Good", "Severe", "Medium"],
  72. },
  73. {
  74. "dps": COUNTDOWN_DPS,
  75. "name": "sensor_timer",
  76. "unit": UnitOfTime.MINUTES,
  77. "device_class": SensorDeviceClass.DURATION,
  78. },
  79. {
  80. "dps": FILTER_DPS,
  81. "name": "sensor_filter",
  82. "unit": PERCENTAGE,
  83. },
  84. ]
  85. )
  86. self.mark_secondary(
  87. [
  88. "binary_sensor_error",
  89. "button_filter_reset",
  90. "light",
  91. "select_timer",
  92. "sensor_air_quality",
  93. "sensor_filter",
  94. "sensor_timer",
  95. "switch_filter_reset",
  96. ]
  97. )
  98. def test_supported_features(self):
  99. self.assertEqual(
  100. self.subject.supported_features,
  101. FanEntityFeature.PRESET_MODE,
  102. )
  103. def test_preset_modes(self):
  104. self.assertCountEqual(
  105. self.subject.preset_modes,
  106. ["Low", "Mid", "High", "Auto", "Sleep"],
  107. )
  108. def test_preset_mode(self):
  109. self.dps[MODE_DPS] = "low"
  110. self.assertEqual(self.subject.preset_mode, "Low")
  111. self.dps[MODE_DPS] = "mid"
  112. self.assertEqual(self.subject.preset_mode, "Mid")
  113. self.dps[MODE_DPS] = "high"
  114. self.assertEqual(self.subject.preset_mode, "High")
  115. self.dps[MODE_DPS] = "auto"
  116. self.assertEqual(self.subject.preset_mode, "Auto")
  117. self.dps[MODE_DPS] = "sleep"
  118. self.assertEqual(self.subject.preset_mode, "Sleep")
  119. async def test_set_preset_to_low(self):
  120. async with assert_device_properties_set(
  121. self.subject._device,
  122. {MODE_DPS: "low"},
  123. ):
  124. await self.subject.async_set_preset_mode("Low")
  125. async def test_set_preset_to_auto(self):
  126. async with assert_device_properties_set(
  127. self.subject._device,
  128. {MODE_DPS: "auto"},
  129. ):
  130. await self.subject.async_set_preset_mode("Auto")
  131. async def test_set_preset_to_sleep(self):
  132. async with assert_device_properties_set(
  133. self.subject._device,
  134. {MODE_DPS: "sleep"},
  135. ):
  136. await self.subject.async_set_preset_mode("Sleep")