test_arlec_fan_light.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. from homeassistant.components.fan import (
  2. DIRECTION_FORWARD,
  3. DIRECTION_REVERSE,
  4. FanEntityFeature,
  5. )
  6. from homeassistant.components.light import (
  7. ATTR_BRIGHTNESS,
  8. ATTR_COLOR_TEMP,
  9. ColorMode,
  10. )
  11. from ..const import ARLEC_FAN_LIGHT_PAYLOAD
  12. from ..helpers import assert_device_properties_set
  13. from ..mixins.select import BasicSelectTests
  14. from ..mixins.switch import SwitchableTests
  15. from .base_device_tests import TuyaDeviceTestCase
  16. SWITCH_DPS = "1"
  17. SPEED_DPS = "3"
  18. DIRECTION_DPS = "4"
  19. LIGHT_DPS = "9"
  20. BRIGHTNESS_DPS = "10"
  21. COLORTEMP_DPS = "11"
  22. PRESET_DPS = "102"
  23. TIMER_DPS = "103"
  24. class TestArlecFan(SwitchableTests, BasicSelectTests, TuyaDeviceTestCase):
  25. __test__ = True
  26. def setUp(self):
  27. self.setUpForConfig("arlec_fan_light.yaml", ARLEC_FAN_LIGHT_PAYLOAD)
  28. self.subject = self.entities.get("fan")
  29. self.light = self.entities.get("light")
  30. self.timer = self.entities.get("select_timer")
  31. self.setUpSwitchable(SWITCH_DPS, self.subject)
  32. self.setUpBasicSelect(
  33. TIMER_DPS,
  34. self.entities["select_timer"],
  35. {
  36. "off": "Off",
  37. "2hour": "2 hours",
  38. "4hour": "4 hours",
  39. "8hour": "8 hours",
  40. },
  41. )
  42. self.mark_secondary(["select_timer"])
  43. def test_supported_features(self):
  44. self.assertEqual(
  45. self.subject.supported_features,
  46. (
  47. FanEntityFeature.DIRECTION
  48. | FanEntityFeature.PRESET_MODE
  49. | FanEntityFeature.SET_SPEED
  50. ),
  51. )
  52. def test_preset_mode(self):
  53. self.dps[PRESET_DPS] = "nature"
  54. self.assertEqual(self.subject.preset_mode, "nature")
  55. self.dps[PRESET_DPS] = "sleep"
  56. self.assertEqual(self.subject.preset_mode, "sleep")
  57. self.dps[PRESET_DPS] = None
  58. self.assertIs(self.subject.preset_mode, None)
  59. def test_preset_modes(self):
  60. self.assertCountEqual(self.subject.preset_modes, ["nature", "sleep"])
  61. async def test_set_preset_mode_to_nature(self):
  62. async with assert_device_properties_set(
  63. self.subject._device,
  64. {PRESET_DPS: "nature"},
  65. ):
  66. await self.subject.async_set_preset_mode("nature")
  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_light_is_on(self):
  102. self.dps[LIGHT_DPS] = False
  103. self.assertFalse(self.light.is_on)
  104. self.dps[LIGHT_DPS] = True
  105. self.assertTrue(self.light.is_on)
  106. def test_light_supported_color_modes(self):
  107. self.assertCountEqual(
  108. self.light.supported_color_modes,
  109. [ColorMode.COLOR_TEMP],
  110. )
  111. def test_light_color_mode(self):
  112. self.assertEqual(self.light.color_mode, ColorMode.COLOR_TEMP)
  113. def test_light_brightness(self):
  114. self.dps[BRIGHTNESS_DPS] = 50
  115. self.assertAlmostEqual(self.light.brightness, 128, 0)
  116. def test_light_color_temp(self):
  117. self.dps[COLORTEMP_DPS] = 70
  118. self.assertEqual(self.light.color_temp, 396)
  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=396,
  127. )