4
0

test_lexy_f501_fan.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. ),
  56. )
  57. def test_preset_mode(self):
  58. self.dps[PRESET_DPS] = "forestwindhigh"
  59. self.assertEqual(self.subject.preset_mode, "strong")
  60. self.dps[PRESET_DPS] = "forestwindlow"
  61. self.assertEqual(self.subject.preset_mode, "nature")
  62. self.dps[PRESET_DPS] = "sleepwindlow"
  63. self.assertEqual(self.subject.preset_mode, "sleep")
  64. self.dps[PRESET_DPS] = "sleepwindhigh"
  65. self.assertEqual(self.subject.preset_mode, "fresh")
  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. ["strong", "nature", "fresh", "sleep"],
  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("strong")
  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("nature")
  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("fresh")
  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")
  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")