test_arlec_fan_light.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. from homeassistant.components.fan import (
  2. DIRECTION_FORWARD,
  3. DIRECTION_REVERSE,
  4. FanEntityFeature,
  5. )
  6. from homeassistant.components.light import ColorMode
  7. from ..const import ARLEC_FAN_LIGHT_PAYLOAD
  8. from ..helpers import assert_device_properties_set
  9. from ..mixins.select import BasicSelectTests
  10. from ..mixins.switch import SwitchableTests
  11. from .base_device_tests import TuyaDeviceTestCase
  12. SWITCH_DPS = "1"
  13. SPEED_DPS = "3"
  14. DIRECTION_DPS = "4"
  15. LIGHT_DPS = "9"
  16. BRIGHTNESS_DPS = "10"
  17. COLORTEMP_DPS = "11"
  18. PRESET_DPS = "102"
  19. TIMER_DPS = "103"
  20. class TestArlecFan(SwitchableTests, BasicSelectTests, TuyaDeviceTestCase):
  21. __test__ = True
  22. def setUp(self):
  23. self.setUpForConfig("arlec_fan_light.yaml", ARLEC_FAN_LIGHT_PAYLOAD)
  24. self.subject = self.entities.get("fan")
  25. self.light = self.entities.get("light")
  26. self.timer = self.entities.get("select_timer")
  27. self.setUpSwitchable(SWITCH_DPS, self.subject)
  28. self.setUpBasicSelect(
  29. TIMER_DPS,
  30. self.entities["select_timer"],
  31. {
  32. "off": "cancel",
  33. "2hour": "2h",
  34. "4hour": "4h",
  35. "8hour": "8h",
  36. },
  37. )
  38. self.mark_secondary(["select_timer"])
  39. def test_supported_features(self):
  40. self.assertEqual(
  41. self.subject.supported_features,
  42. (
  43. FanEntityFeature.DIRECTION
  44. | FanEntityFeature.PRESET_MODE
  45. | FanEntityFeature.SET_SPEED
  46. | FanEntityFeature.TURN_ON
  47. | FanEntityFeature.TURN_OFF
  48. ),
  49. )
  50. def test_preset_mode(self):
  51. self.dps[PRESET_DPS] = "nature"
  52. self.assertEqual(self.subject.preset_mode, "nature")
  53. self.dps[PRESET_DPS] = "sleep"
  54. self.assertEqual(self.subject.preset_mode, "sleep")
  55. self.dps[PRESET_DPS] = None
  56. self.assertIs(self.subject.preset_mode, None)
  57. def test_preset_modes(self):
  58. self.assertCountEqual(self.subject.preset_modes, ["nature", "sleep"])
  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_direction(self):
  72. self.dps[DIRECTION_DPS] = "forward"
  73. self.assertEqual(self.subject.current_direction, DIRECTION_FORWARD)
  74. self.dps[DIRECTION_DPS] = "reverse"
  75. self.assertEqual(self.subject.current_direction, DIRECTION_REVERSE)
  76. async def test_set_direction_forward(self):
  77. async with assert_device_properties_set(
  78. self.subject._device, {DIRECTION_DPS: "forward"}
  79. ):
  80. await self.subject.async_set_direction(DIRECTION_FORWARD)
  81. async def test_set_direction_reverse(self):
  82. async with assert_device_properties_set(
  83. self.subject._device, {DIRECTION_DPS: "reverse"}
  84. ):
  85. await self.subject.async_set_direction(DIRECTION_REVERSE)
  86. def test_speed(self):
  87. self.dps[SPEED_DPS] = "3"
  88. self.assertEqual(self.subject.percentage, 50)
  89. def test_speed_step(self):
  90. self.assertAlmostEqual(self.subject.percentage_step, 16.67, 2)
  91. self.assertEqual(self.subject.speed_count, 6)
  92. async def test_set_speed(self):
  93. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 2}):
  94. await self.subject.async_set_percentage(33)
  95. async def test_set_speed_in_normal_mode_snaps(self):
  96. self.dps[PRESET_DPS] = "normal"
  97. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 5}):
  98. await self.subject.async_set_percentage(80)
  99. def test_light_is_on(self):
  100. self.dps[LIGHT_DPS] = False
  101. self.assertFalse(self.light.is_on)
  102. self.dps[LIGHT_DPS] = True
  103. self.assertTrue(self.light.is_on)
  104. def test_light_supported_color_modes(self):
  105. self.assertCountEqual(
  106. self.light.supported_color_modes,
  107. [ColorMode.COLOR_TEMP],
  108. )
  109. def test_light_color_mode(self):
  110. self.assertEqual(self.light.color_mode, ColorMode.COLOR_TEMP)
  111. def test_light_brightness(self):
  112. self.dps[BRIGHTNESS_DPS] = 50
  113. self.assertAlmostEqual(self.light.brightness, 129, 0)
  114. def test_light_color_temp(self):
  115. self.dps[COLORTEMP_DPS] = 70
  116. self.assertEqual(self.light.color_temp_kelvin, 3840)
  117. def test_light_color_temp_range(self):
  118. self.assertEqual(self.light.min_color_temp_kelvin, 2700)
  119. self.assertEqual(self.light.max_color_temp_kelvin, 6500)
  120. async def test_light_async_turn_on(self):
  121. async with assert_device_properties_set(
  122. self.light._device,
  123. {LIGHT_DPS: True, BRIGHTNESS_DPS: 44, COLORTEMP_DPS: 70},
  124. ):
  125. await self.light.async_turn_on(
  126. brightness=112,
  127. color_temp_kelvin=3840,
  128. )