test_lexy_f501_fan.py 5.5 KB

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