test_arlec_fan_light.py 5.3 KB

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