test_arlec_fan_light.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. from homeassistant.components.fan import (
  2. DIRECTION_FORWARD,
  3. DIRECTION_REVERSE,
  4. FanEntityFeature,
  5. )
  6. from homeassistant.components.light import ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, 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": "Off",
  33. "2hour": "2 hours",
  34. "4hour": "4 hours",
  35. "8hour": "8 hours",
  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. ),
  47. )
  48. def test_preset_mode(self):
  49. self.dps[PRESET_DPS] = "nature"
  50. self.assertEqual(self.subject.preset_mode, "nature")
  51. self.dps[PRESET_DPS] = "sleep"
  52. self.assertEqual(self.subject.preset_mode, "sleep")
  53. self.dps[PRESET_DPS] = None
  54. self.assertIs(self.subject.preset_mode, None)
  55. def test_preset_modes(self):
  56. self.assertCountEqual(self.subject.preset_modes, ["nature", "sleep"])
  57. async def test_set_preset_mode_to_nature(self):
  58. async with assert_device_properties_set(
  59. self.subject._device,
  60. {PRESET_DPS: "nature"},
  61. ):
  62. await self.subject.async_set_preset_mode("nature")
  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_light_is_on(self):
  98. self.dps[LIGHT_DPS] = False
  99. self.assertFalse(self.light.is_on)
  100. self.dps[LIGHT_DPS] = True
  101. self.assertTrue(self.light.is_on)
  102. def test_light_supported_color_modes(self):
  103. self.assertCountEqual(
  104. self.light.supported_color_modes,
  105. [ColorMode.COLOR_TEMP],
  106. )
  107. def test_light_color_mode(self):
  108. self.assertEqual(self.light.color_mode, ColorMode.COLOR_TEMP)
  109. def test_light_brightness(self):
  110. self.dps[BRIGHTNESS_DPS] = 50
  111. self.assertAlmostEqual(self.light.brightness, 128, 0)
  112. def test_light_color_temp(self):
  113. self.dps[COLORTEMP_DPS] = 70
  114. self.assertEqual(self.light.color_temp_kelvin, 3840)
  115. def test_light_color_temp_range(self):
  116. self.assertEqual(self.light.min_color_temp_kelvin, 2700)
  117. self.assertEqual(self.light.max_color_temp_kelvin, 6500)
  118. async def test_light_async_turn_on(self):
  119. async with assert_device_properties_set(
  120. self.light._device,
  121. {LIGHT_DPS: True, BRIGHTNESS_DPS: 44, COLORTEMP_DPS: 70},
  122. ):
  123. await self.light.async_turn_on(
  124. brightness=112,
  125. color_temp_kelvin=3840,
  126. )