test_anko_fan.py 4.0 KB

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