test_lexy_f501_fan.py 5.6 KB

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