test_tmwf02_fan.py 1.9 KB

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