test_lexy_f501_fan.py 5.6 KB

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