test_anko_fan.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. from homeassistant.components.fan import FanEntityFeature
  2. from homeassistant.const import TIME_SECONDS
  3. from ..const import ANKO_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. PRESET_DPS = "2"
  10. SPEED_DPS = "3"
  11. OSCILLATE_DPS = "4"
  12. TIMER_DPS = "6"
  13. class TestAnkoFan(SwitchableTests, BasicNumberTests, TuyaDeviceTestCase):
  14. __test__ = True
  15. def setUp(self):
  16. self.setUpForConfig("anko_fan.yaml", ANKO_FAN_PAYLOAD)
  17. self.subject = self.entities["fan"]
  18. self.setUpSwitchable(SWITCH_DPS, self.subject)
  19. self.setUpBasicNumber(
  20. TIMER_DPS,
  21. self.entities.get("number_timer"),
  22. max=9,
  23. unit=TIME_SECONDS,
  24. )
  25. self.mark_secondary(["number_timer"])
  26. def test_supported_features(self):
  27. self.assertEqual(
  28. self.subject.supported_features,
  29. FanEntityFeature.OSCILLATE
  30. | FanEntityFeature.PRESET_MODE
  31. | FanEntityFeature.SET_SPEED,
  32. )
  33. def test_preset_mode(self):
  34. self.dps[PRESET_DPS] = "normal"
  35. self.assertEqual(self.subject.preset_mode, "normal")
  36. self.dps[PRESET_DPS] = "nature"
  37. self.assertEqual(self.subject.preset_mode, "nature")
  38. self.dps[PRESET_DPS] = "sleep"
  39. self.assertEqual(self.subject.preset_mode, "sleep")
  40. self.dps[PRESET_DPS] = None
  41. self.assertIs(self.subject.preset_mode, None)
  42. def test_preset_modes(self):
  43. self.assertCountEqual(self.subject.preset_modes, ["normal", "nature", "sleep"])
  44. async def test_set_preset_mode_to_normal(self):
  45. async with assert_device_properties_set(
  46. self.subject._device,
  47. {PRESET_DPS: "normal"},
  48. ):
  49. await self.subject.async_set_preset_mode("normal")
  50. async def test_set_preset_mode_to_nature(self):
  51. async with assert_device_properties_set(
  52. self.subject._device,
  53. {PRESET_DPS: "nature"},
  54. ):
  55. await self.subject.async_set_preset_mode("nature")
  56. async def test_set_preset_mode_to_sleep(self):
  57. async with assert_device_properties_set(
  58. self.subject._device,
  59. {PRESET_DPS: "sleep"},
  60. ):
  61. await self.subject.async_set_preset_mode("sleep")
  62. def test_oscillating(self):
  63. self.dps[OSCILLATE_DPS] = "off"
  64. self.assertFalse(self.subject.oscillating)
  65. self.dps[OSCILLATE_DPS] = "auto"
  66. self.assertTrue(self.subject.oscillating)
  67. self.dps[OSCILLATE_DPS] = None
  68. self.assertFalse(self.subject.oscillating)
  69. async def test_oscillate_off(self):
  70. async with assert_device_properties_set(
  71. self.subject._device, {OSCILLATE_DPS: "off"}
  72. ):
  73. await self.subject.async_oscillate(False)
  74. async def test_oscillate_on(self):
  75. async with assert_device_properties_set(
  76. self.subject._device, {OSCILLATE_DPS: "auto"}
  77. ):
  78. await self.subject.async_oscillate(True)
  79. def test_speed(self):
  80. self.dps[PRESET_DPS] = "normal"
  81. self.dps[SPEED_DPS] = "4"
  82. self.assertEqual(self.subject.percentage, 50)
  83. def test_speed_step(self):
  84. self.assertEqual(self.subject.percentage_step, 12.5)
  85. self.assertEqual(self.subject.speed_count, 8)
  86. async def test_set_speed_in_normal_mode(self):
  87. self.dps[PRESET_DPS] = "normal"
  88. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 2}):
  89. await self.subject.async_set_percentage(25)
  90. async def test_set_speed_in_normal_mode_snaps(self):
  91. self.dps[PRESET_DPS] = "normal"
  92. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 6}):
  93. await self.subject.async_set_percentage(80)
  94. def test_extra_state_attributes(self):
  95. self.dps[TIMER_DPS] = "5"
  96. self.assertEqual(self.subject.extra_state_attributes, {"timer": 5})