test_immax_neo_light_vento.py 3.8 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. __test__ = True
  29. def setUp(self):
  30. self.setUpForConfig("immax_neo_light_vento.yaml", IMAX_NEO_LIGHT_VENTO_PAYLOAD)
  31. self.fan = self.entities["fan"]
  32. self.light = self.entities["light"]
  33. self.stop_timer = self.entities["select_timer"]
  34. self.setUpSwitchable(SWITCH_DPS, self.fan)
  35. self.setUpBasicLight(LIGHT_DPS, self.light)
  36. self.setUpBasicSelect(
  37. TIMER_DPS,
  38. self.stop_timer,
  39. {
  40. "off": "Off",
  41. "1hour": "1 hour",
  42. "2hour": "2 hours",
  43. "4hour": "4 hours",
  44. "8hour": "8 hours",
  45. },
  46. )
  47. self.mark_secondary(["select_timer"])
  48. def test_supported_features(self):
  49. self.assertEqual(
  50. self.fan.supported_features,
  51. FanEntityFeature.DIRECTION
  52. | FanEntityFeature.PRESET_MODE
  53. | FanEntityFeature.SET_SPEED,
  54. )
  55. def test_preset_modes(self):
  56. self.assertCountEqual(self.fan.preset_modes, ["normal", "nature", "sleep"])
  57. def test_speed(self):
  58. self.dps[SPEED_DPS] = 2
  59. self.assertAlmostEqual(33.3, self.fan.percentage, 1)
  60. self.dps[SPEED_DPS] = 3
  61. self.assertEqual(50, self.fan.percentage)
  62. self.dps[SPEED_DPS] = 4
  63. self.assertAlmostEqual(66.7, self.fan.percentage, 1)
  64. self.dps[SPEED_DPS] = 5
  65. self.assertAlmostEqual(83.3, self.fan.percentage, 1)
  66. self.dps[SPEED_DPS] = 6
  67. self.assertEqual(100, self.fan.percentage)
  68. self.dps[SPEED_DPS] = 0
  69. self.assertEqual(0, self.fan.percentage)
  70. def test_preset_mode(self):
  71. self.dps[PRESET_DPS] = "normal"
  72. self.assertEqual(self.fan.preset_mode, "normal")
  73. self.dps[PRESET_DPS] = "nature"
  74. self.assertEqual(self.fan.preset_mode, "nature")
  75. self.dps[PRESET_DPS] = "sleep"
  76. self.assertEqual(self.fan.preset_mode, "sleep")
  77. def test_direction(self):
  78. self.dps[DIRECTION_DPS] = "forward"
  79. self.assertEqual(self.fan.current_direction, DIRECTION_FORWARD)
  80. self.dps[DIRECTION_DPS] = "reverse"
  81. self.assertEqual(self.fan.current_direction, DIRECTION_REVERSE)
  82. async def test_set_direction_forward(self):
  83. async with assert_device_properties_set(
  84. self.fan._device, {DIRECTION_DPS: "forward"}
  85. ):
  86. await self.fan.async_set_direction(DIRECTION_FORWARD)
  87. async def test_set_direction_reverse(self):
  88. async with assert_device_properties_set(
  89. self.fan._device, {DIRECTION_DPS: "reverse"}
  90. ):
  91. await self.fan.async_set_direction(DIRECTION_REVERSE)
  92. def test_set_stop_timer(self):
  93. self.dps[TIMER_DPS] = "2hour"
  94. self.assertEqual(self.stop_timer.current_option, "2 hours")
  95. async def test_set_speed(self):
  96. async with assert_device_properties_set(self.fan._device, {SPEED_DPS: 2}):
  97. await self.fan.async_set_percentage(33)
  98. async def test_set_speed_in_normal_mode_snaps(self):
  99. self.dps[PRESET_DPS] = "normal"
  100. async with assert_device_properties_set(self.fan._device, {SPEED_DPS: 5}):
  101. await self.fan.async_set_percentage(80)