test_tmwf02_fan.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from homeassistant.components.fan import FanEntityFeature
  2. from ..const import TMWF02_FAN_PAYLOAD
  3. from ..helpers import assert_device_properties_set
  4. from ..mixins.switch import SwitchableTests
  5. from .base_device_tests import TuyaDeviceTestCase
  6. SWITCH_DPS = "1"
  7. TIMER_DPS = "2"
  8. LEVEL_DPS = "3"
  9. SPEED_DPS = "4"
  10. class TestTMWF02Fan(SwitchableTests, TuyaDeviceTestCase):
  11. __test__ = True
  12. def setUp(self):
  13. self.setUpForConfig("tmwf02_fan.yaml", TMWF02_FAN_PAYLOAD)
  14. self.subject = self.entities["fan"]
  15. self.setUpSwitchable(SWITCH_DPS, self.subject)
  16. self.mark_secondary(["time_timer"])
  17. def test_supported_features(self):
  18. self.assertEqual(
  19. self.subject.supported_features,
  20. FanEntityFeature.SET_SPEED
  21. | FanEntityFeature.TURN_ON
  22. | FanEntityFeature.TURN_OFF,
  23. )
  24. def test_speed(self):
  25. self.dps[SPEED_DPS] = 35
  26. self.assertEqual(self.subject.percentage, 35)
  27. def test_speed_step(self):
  28. self.assertEqual(self.subject.percentage_step, 1)
  29. async def test_set_speed(self):
  30. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 70}):
  31. await self.subject.async_set_percentage(70)
  32. async def test_set_speed_snaps(self):
  33. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 25}):
  34. await self.subject.async_set_percentage(24.8)
  35. def test_extra_state_attributes(self):
  36. self.dps[LEVEL_DPS] = "level_3"
  37. self.assertDictEqual(
  38. self.subject.extra_state_attributes,
  39. {"fan_level": "level_3"},
  40. )