test_deta_fan.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from homeassistant.components.fan import FanEntityFeature
  2. from ..const import DETA_FAN_PAYLOAD
  3. from ..helpers import assert_device_properties_set
  4. from ..mixins.light import BasicLightTests
  5. from ..mixins.switch import BasicSwitchTests, SwitchableTests
  6. from .base_device_tests import TuyaDeviceTestCase
  7. SWITCH_DPS = "1"
  8. SPEED_DPS = "3"
  9. LIGHT_DPS = "9"
  10. MASTER_DPS = "101"
  11. TIMER_DPS = "102"
  12. LIGHT_TIMER_DPS = "103"
  13. class TestDetaFan(
  14. BasicLightTests, BasicSwitchTests, SwitchableTests, TuyaDeviceTestCase
  15. ):
  16. __test__ = True
  17. def setUp(self):
  18. self.setUpForConfig("deta_fan.yaml", DETA_FAN_PAYLOAD)
  19. self.subject = self.entities["fan"]
  20. self.setUpSwitchable(SWITCH_DPS, self.subject)
  21. self.setUpBasicLight(LIGHT_DPS, self.entities["light"])
  22. self.setUpBasicSwitch(MASTER_DPS, self.entities["switch_master"])
  23. self.mark_secondary(["switch_master"])
  24. def test_supported_features(self):
  25. self.assertEqual(
  26. self.subject.supported_features,
  27. FanEntityFeature.SET_SPEED
  28. | FanEntityFeature.TURN_ON
  29. | FanEntityFeature.TURN_OFF,
  30. )
  31. def test_speed(self):
  32. self.dps[SPEED_DPS] = "1"
  33. self.assertAlmostEqual(self.subject.percentage, 33, 0)
  34. def test_speed_step(self):
  35. self.assertAlmostEqual(self.subject.percentage_step, 33.3, 1)
  36. async def test_set_speed(self):
  37. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 2}):
  38. await self.subject.async_set_percentage(66.7)
  39. async def test_auto_stringify_speed(self):
  40. self.dps[SPEED_DPS] = "1"
  41. self.assertAlmostEqual(self.subject.percentage, 33, 0)
  42. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: "2"}):
  43. await self.subject.async_set_percentage(66.7)
  44. async def test_set_speed_snaps(self):
  45. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 2}):
  46. await self.subject.async_set_percentage(55)
  47. def test_extra_state_attributes(self):
  48. self.dps[TIMER_DPS] = "5"
  49. self.assertEqual(self.subject.extra_state_attributes, {"timer": 5})
  50. def test_basic_light_state_attributes(self):
  51. self.dps[LIGHT_TIMER_DPS] = "6"
  52. self.assertEqual(self.basicLight.extra_state_attributes, {"timer": 6})