test_anko_fan.py 3.8 KB

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