test_arlec_fan.py 4.1 KB

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