4
0

test_arlec_fan.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 TuyaDeviceTestCase
  12. SWITCH_DPS = "1"
  13. SPEED_DPS = "3"
  14. DIRECTION_DPS = "4"
  15. PRESET_DPS = "102"
  16. TIMER_DPS = "103"
  17. class TestArlecFan(TuyaDeviceTestCase):
  18. __test__ = True
  19. def setUp(self):
  20. self.setUpForConfig("arlec_fan.yaml", ARLEC_FAN_PAYLOAD)
  21. self.subject = self.entities["fan"]
  22. def test_supported_features(self):
  23. self.assertEqual(
  24. self.subject.supported_features,
  25. SUPPORT_DIRECTION | SUPPORT_PRESET_MODE | SUPPORT_SET_SPEED,
  26. )
  27. def test_is_on(self):
  28. self.dps[SWITCH_DPS] = True
  29. self.assertTrue(self.subject.is_on)
  30. self.dps[SWITCH_DPS] = False
  31. self.assertFalse(self.subject.is_on)
  32. self.dps[SWITCH_DPS] = None
  33. self.assertEqual(self.subject.is_on, STATE_UNAVAILABLE)
  34. async def test_turn_on(self):
  35. async with assert_device_properties_set(
  36. self.subject._device, {SWITCH_DPS: True}
  37. ):
  38. await self.subject.async_turn_on()
  39. async def test_turn_off(self):
  40. async with assert_device_properties_set(
  41. self.subject._device, {SWITCH_DPS: False}
  42. ):
  43. await self.subject.async_turn_off()
  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, "breeze")
  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", "breeze", "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("breeze")
  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)
  101. def test_device_state_attributes(self):
  102. self.dps[TIMER_DPS] = "2hour"
  103. self.assertEqual(self.subject.device_state_attributes, {"timer": "2hour"})