test_arlec_fan.py 4.4 KB

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