test_vork_vk6067aw_purifier.py 4.9 KB

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