test_deta_fan.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. self.mark_secondary(["switch_master"])
  25. def test_supported_features(self):
  26. self.assertEqual(
  27. self.subject.supported_features,
  28. SUPPORT_SET_SPEED,
  29. )
  30. def test_speed(self):
  31. self.dps[SPEED_DPS] = "1"
  32. self.assertAlmostEqual(self.subject.percentage, 33.3, 1)
  33. def test_speed_step(self):
  34. self.assertAlmostEqual(self.subject.percentage_step, 33.3, 1)
  35. async def test_set_speed(self):
  36. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 2}):
  37. await self.subject.async_set_percentage(66.7)
  38. async def test_auto_stringify_speed(self):
  39. self.dps[SPEED_DPS] = "1"
  40. self.assertAlmostEqual(self.subject.percentage, 33.3, 1)
  41. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: "2"}):
  42. await self.subject.async_set_percentage(66.7)
  43. async def test_set_speed_snaps(self):
  44. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 2}):
  45. await self.subject.async_set_percentage(55)
  46. def test_extra_state_attributes(self):
  47. self.dps[TIMER_DPS] = "5"
  48. self.assertEqual(self.subject.extra_state_attributes, {"timer": 5})
  49. def test_basic_light_state_attributes(self):
  50. self.dps[LIGHT_TIMER_DPS] = "6"
  51. self.assertEqual(self.basicLight.extra_state_attributes, {"timer": 6})