4
0

test_arlec_fan.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. from homeassistant.components.fan import (
  2. DIRECTION_FORWARD,
  3. DIRECTION_REVERSE,
  4. FanEntityFeature,
  5. )
  6. from ..const import ARLEC_FAN_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from ..mixins.select import BasicSelectTests
  9. from ..mixins.switch import SwitchableTests
  10. from .base_device_tests import TuyaDeviceTestCase
  11. SWITCH_DPS = "1"
  12. SPEED_DPS = "3"
  13. DIRECTION_DPS = "4"
  14. PRESET_DPS = "102"
  15. TIMER_DPS = "103"
  16. class TestArlecFan(SwitchableTests, BasicSelectTests, TuyaDeviceTestCase):
  17. def setUp(self):
  18. self.setUpForConfig("arlec_fan.yaml", ARLEC_FAN_PAYLOAD)
  19. self.subject = self.entities["fan"]
  20. self.timer = self.entities["select_timer"]
  21. self.setUpSwitchable(SWITCH_DPS, self.subject)
  22. self.setUpBasicSelect(
  23. TIMER_DPS,
  24. self.entities["select_timer"],
  25. {
  26. "off": "cancel",
  27. "2hour": "2h",
  28. "4hour": "4h",
  29. "8hour": "8h",
  30. },
  31. )
  32. self.mark_secondary(["select_timer"])
  33. def test_supported_features(self):
  34. self.assertEqual(
  35. self.subject.supported_features,
  36. (
  37. FanEntityFeature.DIRECTION
  38. | FanEntityFeature.PRESET_MODE
  39. | FanEntityFeature.SET_SPEED
  40. | FanEntityFeature.TURN_OFF
  41. | FanEntityFeature.TURN_ON
  42. ),
  43. )
  44. def test_preset_mode(self):
  45. self.dps[PRESET_DPS] = "normal"
  46. self.assertEqual(self.subject.preset_mode, "normal")
  47. self.dps[PRESET_DPS] = "breeze"
  48. self.assertEqual(self.subject.preset_mode, "nature")
  49. self.dps[PRESET_DPS] = "sleep"
  50. self.assertEqual(self.subject.preset_mode, "sleep")
  51. self.dps[PRESET_DPS] = None
  52. self.assertIs(self.subject.preset_mode, None)
  53. def test_preset_modes(self):
  54. self.assertCountEqual(self.subject.preset_modes, ["normal", "nature", "sleep"])
  55. async def test_set_preset_mode_to_normal(self):
  56. async with assert_device_properties_set(
  57. self.subject._device,
  58. {PRESET_DPS: "normal"},
  59. ):
  60. await self.subject.async_set_preset_mode("normal")
  61. async def test_set_preset_mode_to_breeze(self):
  62. async with assert_device_properties_set(
  63. self.subject._device,
  64. {PRESET_DPS: "breeze"},
  65. ):
  66. await self.subject.async_set_preset_mode("nature")
  67. async def test_set_preset_mode_to_sleep(self):
  68. async with assert_device_properties_set(
  69. self.subject._device,
  70. {PRESET_DPS: "sleep"},
  71. ):
  72. await self.subject.async_set_preset_mode("sleep")
  73. def test_direction(self):
  74. self.dps[DIRECTION_DPS] = "forward"
  75. self.assertEqual(self.subject.current_direction, DIRECTION_FORWARD)
  76. self.dps[DIRECTION_DPS] = "reverse"
  77. self.assertEqual(self.subject.current_direction, DIRECTION_REVERSE)
  78. async def test_set_direction_forward(self):
  79. async with assert_device_properties_set(
  80. self.subject._device, {DIRECTION_DPS: "forward"}
  81. ):
  82. await self.subject.async_set_direction(DIRECTION_FORWARD)
  83. async def test_set_direction_reverse(self):
  84. async with assert_device_properties_set(
  85. self.subject._device, {DIRECTION_DPS: "reverse"}
  86. ):
  87. await self.subject.async_set_direction(DIRECTION_REVERSE)
  88. def test_speed(self):
  89. self.dps[SPEED_DPS] = "3"
  90. self.assertEqual(self.subject.percentage, 50)
  91. def test_speed_step(self):
  92. self.assertAlmostEqual(self.subject.percentage_step, 16.67, 2)
  93. self.assertEqual(self.subject.speed_count, 6)
  94. async def test_set_speed(self):
  95. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 2}):
  96. await self.subject.async_set_percentage(33)
  97. async def test_set_speed_in_normal_mode_snaps(self):
  98. self.dps[PRESET_DPS] = "normal"
  99. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 5}):
  100. await self.subject.async_set_percentage(80)