test_tmwf02_fan.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. )
  31. def test_speed(self):
  32. self.dps[SPEED_DPS] = 35
  33. self.assertEqual(self.subject.percentage, 35)
  34. def test_speed_step(self):
  35. self.assertEqual(self.subject.percentage_step, 1)
  36. async def test_set_speed(self):
  37. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 70}):
  38. await self.subject.async_set_percentage(70)
  39. async def test_set_speed_snaps(self):
  40. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 25}):
  41. await self.subject.async_set_percentage(24.8)
  42. def test_extra_state_attributes(self):
  43. self.dps[LEVEL_DPS] = "level_3"
  44. self.assertDictEqual(
  45. self.subject.extra_state_attributes,
  46. {"fan_level": "level_3"},
  47. )