test_anko_fan.py 4.3 KB

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