test_immax_neo_light_vento.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. from homeassistant.components.fan import (
  2. DIRECTION_FORWARD,
  3. DIRECTION_REVERSE,
  4. FanEntityFeature,
  5. )
  6. from ..helpers import assert_device_properties_set
  7. from ..mixins.light import BasicLightTests
  8. from ..mixins.select import BasicSelectTests
  9. from ..mixins.switch import SwitchableTests
  10. from .base_device_tests import TuyaDeviceTestCase
  11. IMAX_NEO_LIGHT_VENTO_PAYLOAD = {
  12. "1": True,
  13. "2": "normal",
  14. "3": "1",
  15. "8": "forward",
  16. "15": False,
  17. "22": "off",
  18. }
  19. SWITCH_DPS = "1"
  20. PRESET_DPS = "2"
  21. SPEED_DPS = "3"
  22. DIRECTION_DPS = "8"
  23. LIGHT_DPS = "15"
  24. TIMER_DPS = "22"
  25. class TestImmaxNeoLightVento(
  26. SwitchableTests, BasicSelectTests, BasicLightTests, TuyaDeviceTestCase
  27. ):
  28. def setUp(self):
  29. self.setUpForConfig("immax_neo_light_vento.yaml", IMAX_NEO_LIGHT_VENTO_PAYLOAD)
  30. self.fan = self.entities["fan"]
  31. self.light = self.entities["light"]
  32. self.stop_timer = self.entities["select_timer"]
  33. self.setUpSwitchable(SWITCH_DPS, self.fan)
  34. self.setUpBasicLight(LIGHT_DPS, self.light)
  35. self.setUpBasicSelect(
  36. TIMER_DPS,
  37. self.stop_timer,
  38. {
  39. "off": "cancel",
  40. "1hour": "1h",
  41. "2hour": "2h",
  42. "4hour": "4h",
  43. "8hour": "8h",
  44. },
  45. )
  46. self.mark_secondary(["select_timer"])
  47. def test_supported_features(self):
  48. self.assertEqual(
  49. self.fan.supported_features,
  50. FanEntityFeature.DIRECTION
  51. | FanEntityFeature.PRESET_MODE
  52. | FanEntityFeature.SET_SPEED
  53. | FanEntityFeature.TURN_OFF
  54. | FanEntityFeature.TURN_ON,
  55. )
  56. def test_preset_modes(self):
  57. self.assertCountEqual(self.fan.preset_modes, ["normal", "nature", "sleep"])
  58. def test_speed(self):
  59. self.dps[SPEED_DPS] = 2
  60. self.assertAlmostEqual(33, self.fan.percentage, 0)
  61. self.dps[SPEED_DPS] = 3
  62. self.assertEqual(50, self.fan.percentage)
  63. self.dps[SPEED_DPS] = 4
  64. self.assertAlmostEqual(66, self.fan.percentage, 0)
  65. self.dps[SPEED_DPS] = 5
  66. self.assertAlmostEqual(83, self.fan.percentage, 0)
  67. self.dps[SPEED_DPS] = 6
  68. self.assertEqual(100, self.fan.percentage)
  69. self.dps[SPEED_DPS] = 0
  70. self.assertEqual(0, self.fan.percentage)
  71. def test_preset_mode(self):
  72. self.dps[PRESET_DPS] = "normal"
  73. self.assertEqual(self.fan.preset_mode, "normal")
  74. self.dps[PRESET_DPS] = "nature"
  75. self.assertEqual(self.fan.preset_mode, "nature")
  76. self.dps[PRESET_DPS] = "sleep"
  77. self.assertEqual(self.fan.preset_mode, "sleep")
  78. def test_direction(self):
  79. self.dps[DIRECTION_DPS] = "forward"
  80. self.assertEqual(self.fan.current_direction, DIRECTION_FORWARD)
  81. self.dps[DIRECTION_DPS] = "reverse"
  82. self.assertEqual(self.fan.current_direction, DIRECTION_REVERSE)
  83. async def test_set_direction_forward(self):
  84. async with assert_device_properties_set(
  85. self.fan._device, {DIRECTION_DPS: "forward"}
  86. ):
  87. await self.fan.async_set_direction(DIRECTION_FORWARD)
  88. async def test_set_direction_reverse(self):
  89. async with assert_device_properties_set(
  90. self.fan._device, {DIRECTION_DPS: "reverse"}
  91. ):
  92. await self.fan.async_set_direction(DIRECTION_REVERSE)
  93. def test_set_stop_timer(self):
  94. self.dps[TIMER_DPS] = "2hour"
  95. self.assertEqual(self.stop_timer.current_option, "2h")
  96. async def test_set_speed(self):
  97. async with assert_device_properties_set(self.fan._device, {SPEED_DPS: 2}):
  98. await self.fan.async_set_percentage(33)
  99. async def test_set_speed_in_normal_mode_snaps(self):
  100. self.dps[PRESET_DPS] = "normal"
  101. async with assert_device_properties_set(self.fan._device, {SPEED_DPS: 5}):
  102. await self.fan.async_set_percentage(80)