test_tmwf02_fan.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. def setUp(self):
  12. self.setUpForConfig("tmwf02_fan.yaml", TMWF02_FAN_PAYLOAD)
  13. self.subject = self.entities["fan"]
  14. self.setUpSwitchable(SWITCH_DPS, self.subject)
  15. self.mark_secondary(["time_timer"])
  16. def test_supported_features(self):
  17. self.assertEqual(
  18. self.subject.supported_features,
  19. FanEntityFeature.SET_SPEED
  20. | FanEntityFeature.TURN_ON
  21. | FanEntityFeature.TURN_OFF,
  22. )
  23. def test_speed(self):
  24. self.dps[SPEED_DPS] = 35
  25. self.assertEqual(self.subject.percentage, 35)
  26. def test_speed_step(self):
  27. self.assertEqual(self.subject.percentage_step, 1)
  28. async def test_set_speed(self):
  29. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 70}):
  30. await self.subject.async_set_percentage(70)
  31. async def test_set_speed_snaps(self):
  32. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 25}):
  33. await self.subject.async_set_percentage(24.8)
  34. def test_extra_state_attributes(self):
  35. self.dps[LEVEL_DPS] = "level_3"
  36. self.assertDictEqual(
  37. self.subject.extra_state_attributes,
  38. {"fan_level": "level_3"},
  39. )