test_lexy_f501_fan.py 5.5 KB

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