test_arlec_fan_light.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.components.light import (
  9. ATTR_BRIGHTNESS,
  10. ATTR_COLOR_TEMP,
  11. COLOR_MODE_COLOR_TEMP,
  12. )
  13. from ..const import ARLEC_FAN_LIGHT_PAYLOAD
  14. from ..helpers import assert_device_properties_set
  15. from ..mixins.select import BasicSelectTests
  16. from ..mixins.switch import SwitchableTests
  17. from .base_device_tests import TuyaDeviceTestCase
  18. SWITCH_DPS = "1"
  19. SPEED_DPS = "3"
  20. DIRECTION_DPS = "4"
  21. LIGHT_DPS = "9"
  22. BRIGHTNESS_DPS = "10"
  23. COLORTEMP_DPS = "11"
  24. PRESET_DPS = "102"
  25. TIMER_DPS = "103"
  26. class TestArlecFan(SwitchableTests, BasicSelectTests, TuyaDeviceTestCase):
  27. __test__ = True
  28. def setUp(self):
  29. self.setUpForConfig("arlec_fan_light.yaml", ARLEC_FAN_LIGHT_PAYLOAD)
  30. self.subject = self.entities.get("fan")
  31. self.light = self.entities.get("light")
  32. self.timer = self.entities.get("select_timer")
  33. self.setUpSwitchable(SWITCH_DPS, self.subject)
  34. self.setUpBasicSelect(
  35. TIMER_DPS,
  36. self.entities["select_timer"],
  37. {
  38. "off": "Off",
  39. "2hour": "2 hours",
  40. "4hour": "4 hours",
  41. "8hour": "8 hours",
  42. },
  43. )
  44. self.mark_secondary(["select_timer"])
  45. def test_supported_features(self):
  46. self.assertEqual(
  47. self.subject.supported_features,
  48. SUPPORT_DIRECTION | SUPPORT_PRESET_MODE | SUPPORT_SET_SPEED,
  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. [COLOR_MODE_COLOR_TEMP],
  108. )
  109. def test_light_color_mode(self):
  110. self.assertEqual(self.light.color_mode, COLOR_MODE_COLOR_TEMP)
  111. def test_light_brightness(self):
  112. self.dps[BRIGHTNESS_DPS] = 50
  113. self.assertAlmostEqual(self.light.brightness, 128, 0)
  114. def test_light_color_temp(self):
  115. self.dps[COLORTEMP_DPS] = 70
  116. self.assertEqual(self.light.color_temp, 396)
  117. async def test_light_async_turn_on(self):
  118. async with assert_device_properties_set(
  119. self.light._device,
  120. {LIGHT_DPS: True, BRIGHTNESS_DPS: 44, COLORTEMP_DPS: 70},
  121. ):
  122. await self.light.async_turn_on(
  123. brightness=112,
  124. color_temp=396,
  125. )