test_lexy_f501_fan.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. from homeassistant.components.fan import (
  2. SUPPORT_OSCILLATE,
  3. SUPPORT_PRESET_MODE,
  4. SUPPORT_SET_SPEED,
  5. )
  6. from ..const import LEXY_F501_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from ..mixins.light import BasicLightTests
  9. from ..mixins.lock import BasicLockTests
  10. from ..mixins.number import BasicNumberTests
  11. from ..mixins.switch import BasicSwitchTests, SwitchableTests
  12. from .base_device_tests import TuyaDeviceTestCase
  13. POWER_DPS = "1"
  14. PRESET_DPS = "2"
  15. OSCILLATE_DPS = "4"
  16. TIMER_DPS = "6"
  17. LIGHT_DPS = "9"
  18. LOCK_DPS = "16"
  19. SWITCH_DPS = "17"
  20. SPEED_DPS = "102"
  21. class TestLexyF501Fan(
  22. SwitchableTests,
  23. BasicLightTests,
  24. BasicLockTests,
  25. BasicNumberTests,
  26. BasicSwitchTests,
  27. TuyaDeviceTestCase,
  28. ):
  29. __test__ = True
  30. def setUp(self):
  31. self.setUpForConfig("lexy_f501_fan.yaml", LEXY_F501_PAYLOAD)
  32. self.subject = self.entities.get("fan")
  33. self.setUpSwitchable(POWER_DPS, self.subject)
  34. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light"))
  35. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  36. self.setUpBasicNumber(TIMER_DPS, self.entities.get("number_timer"), max=7)
  37. self.setUpBasicSwitch(SWITCH_DPS, self.entities.get("switch_sound"))
  38. def test_supported_features(self):
  39. self.assertEqual(
  40. self.subject.supported_features,
  41. SUPPORT_OSCILLATE | SUPPORT_PRESET_MODE | SUPPORT_SET_SPEED,
  42. )
  43. def test_preset_mode(self):
  44. self.dps[PRESET_DPS] = "forestwindhigh"
  45. self.assertEqual(self.subject.preset_mode, "Forest High")
  46. self.dps[PRESET_DPS] = "forestwindlow"
  47. self.assertEqual(self.subject.preset_mode, "Forest Low")
  48. self.dps[PRESET_DPS] = "sleepwindlow"
  49. self.assertEqual(self.subject.preset_mode, "Sleep Low")
  50. self.dps[PRESET_DPS] = "sleepwindhigh"
  51. self.assertEqual(self.subject.preset_mode, "Sleep High")
  52. self.dps[PRESET_DPS] = None
  53. self.assertIs(self.subject.preset_mode, None)
  54. def test_preset_modes(self):
  55. self.assertCountEqual(
  56. self.subject.preset_modes,
  57. ["Forest High", "Forest Low", "Sleep High", "Sleep Low"],
  58. )
  59. async def test_set_preset_mode_to_foresthigh(self):
  60. async with assert_device_properties_set(
  61. self.subject._device,
  62. {PRESET_DPS: "forestwindhigh"},
  63. ):
  64. await self.subject.async_set_preset_mode("Forest High")
  65. async def test_set_preset_mode_to_forestlow(self):
  66. async with assert_device_properties_set(
  67. self.subject._device,
  68. {PRESET_DPS: "forestwindlow"},
  69. ):
  70. await self.subject.async_set_preset_mode("Forest Low")
  71. async def test_set_preset_mode_to_sleephigh(self):
  72. async with assert_device_properties_set(
  73. self.subject._device,
  74. {PRESET_DPS: "sleepwindhigh"},
  75. ):
  76. await self.subject.async_set_preset_mode("Sleep High")
  77. async def test_set_preset_mode_to_sleeplow(self):
  78. async with assert_device_properties_set(
  79. self.subject._device,
  80. {PRESET_DPS: "sleepwindlow"},
  81. ):
  82. await self.subject.async_set_preset_mode("Sleep Low")
  83. def test_oscillating(self):
  84. self.dps[OSCILLATE_DPS] = "off"
  85. self.assertFalse(self.subject.oscillating)
  86. self.dps[OSCILLATE_DPS] = "30"
  87. self.assertTrue(self.subject.oscillating)
  88. self.dps[OSCILLATE_DPS] = "60"
  89. self.assertTrue(self.subject.oscillating)
  90. self.dps[OSCILLATE_DPS] = "90"
  91. self.assertTrue(self.subject.oscillating)
  92. self.dps[OSCILLATE_DPS] = "360positive"
  93. self.assertTrue(self.subject.oscillating)
  94. self.dps[OSCILLATE_DPS] = "360negative"
  95. self.assertTrue(self.subject.oscillating)
  96. self.dps[OSCILLATE_DPS] = None
  97. self.assertFalse(self.subject.oscillating)
  98. async def test_oscillate_off(self):
  99. async with assert_device_properties_set(
  100. self.subject._device, {OSCILLATE_DPS: "off"}
  101. ):
  102. await self.subject.async_oscillate(False)
  103. def test_speed(self):
  104. self.dps[SPEED_DPS] = "6"
  105. self.assertEqual(self.subject.percentage, 40)
  106. def test_speed_step(self):
  107. self.assertAlmostEqual(self.subject.percentage_step, 6.7, 1)
  108. self.assertEqual(self.subject.speed_count, 15)
  109. async def test_set_speed(self):
  110. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 3}):
  111. await self.subject.async_set_percentage(20)
  112. async def test_set_speed_snaps(self):
  113. self.dps[PRESET_DPS] = "normal"
  114. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 12}):
  115. await self.subject.async_set_percentage(78)
  116. def test_device_state_attributes(self):
  117. self.dps[TIMER_DPS] = "5"
  118. self.assertEqual(self.subject.device_state_attributes, {"timer": 5})
  119. def test_icons(self):
  120. self.dps[LIGHT_DPS] = True
  121. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  122. self.dps[LIGHT_DPS] = False
  123. self.assertEqual(self.basicLight.icon, "mdi:led-off")