test_deta_fan.py 2.2 KB

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