test_stirling_fs140dc_fan.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. from homeassistant.components.fan import FanEntityFeature
  2. from ..const import STIRLING_FS1_FAN_PAYLOAD
  3. from ..helpers import assert_device_properties_set
  4. from ..mixins.switch import SwitchableTests
  5. from .base_device_tests import TuyaDeviceTestCase
  6. SWITCH_DPS = "1"
  7. PRESET_DPS = "2"
  8. SPEED_DPS = "3"
  9. OSCILLATE_DPS = "5"
  10. TIMER_DPS = "22"
  11. class TestStirlingFS1Fan(SwitchableTests, TuyaDeviceTestCase):
  12. __test__ = True
  13. def setUp(self):
  14. self.setUpForConfig("stirling_fs140dc_fan.yaml", STIRLING_FS1_FAN_PAYLOAD)
  15. self.subject = self.entities.get("fan")
  16. self.timer = self.entities.get("select_timer")
  17. self.setUpSwitchable(SWITCH_DPS, self.subject)
  18. self.mark_secondary(["select_timer"])
  19. def test_supported_features(self):
  20. self.assertEqual(
  21. self.subject.supported_features,
  22. (
  23. FanEntityFeature.OSCILLATE
  24. | FanEntityFeature.PRESET_MODE
  25. | FanEntityFeature.SET_SPEED
  26. | FanEntityFeature.TURN_OFF
  27. | FanEntityFeature.TURN_ON
  28. ),
  29. )
  30. def test_preset_mode(self):
  31. self.dps[PRESET_DPS] = "normal"
  32. self.assertEqual(self.subject.preset_mode, "normal")
  33. self.dps[PRESET_DPS] = "nature"
  34. self.assertEqual(self.subject.preset_mode, "nature")
  35. self.dps[PRESET_DPS] = "sleep"
  36. self.assertEqual(self.subject.preset_mode, "sleep")
  37. self.dps[PRESET_DPS] = None
  38. self.assertIs(self.subject.preset_mode, None)
  39. def test_preset_modes(self):
  40. self.assertCountEqual(
  41. self.subject.preset_modes,
  42. ["normal", "nature", "sleep"],
  43. )
  44. async def test_set_preset_mode_to_normal(self):
  45. async with assert_device_properties_set(
  46. self.subject._device,
  47. {PRESET_DPS: "normal"},
  48. ):
  49. await self.subject.async_set_preset_mode("normal")
  50. async def test_set_preset_mode_to_nature(self):
  51. async with assert_device_properties_set(
  52. self.subject._device,
  53. {PRESET_DPS: "nature"},
  54. ):
  55. await self.subject.async_set_preset_mode("nature")
  56. async def test_set_preset_mode_to_sleep(self):
  57. async with assert_device_properties_set(
  58. self.subject._device,
  59. {PRESET_DPS: "sleep"},
  60. ):
  61. await self.subject.async_set_preset_mode("sleep")
  62. def test_oscillating(self):
  63. self.dps[OSCILLATE_DPS] = False
  64. self.assertFalse(self.subject.oscillating)
  65. self.dps[OSCILLATE_DPS] = True
  66. self.assertTrue(self.subject.oscillating)
  67. self.dps[OSCILLATE_DPS] = None
  68. self.assertFalse(self.subject.oscillating)
  69. async def test_oscillate_off(self):
  70. async with assert_device_properties_set(
  71. self.subject._device, {OSCILLATE_DPS: False}
  72. ):
  73. await self.subject.async_oscillate(False)
  74. async def test_oscillate_on(self):
  75. async with assert_device_properties_set(
  76. self.subject._device, {OSCILLATE_DPS: True}
  77. ):
  78. await self.subject.async_oscillate(True)
  79. def test_speed(self):
  80. self.dps[SPEED_DPS] = "4"
  81. self.assertAlmostEqual(self.subject.percentage, 26, 0)
  82. def test_speed_step(self):
  83. self.assertAlmostEqual(self.subject.percentage_step, 6.67, 2)
  84. self.assertEqual(self.subject.speed_count, 15)
  85. async def test_set_speed(self):
  86. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 5}):
  87. await self.subject.async_set_percentage(33)
  88. async def test_set_speed_snaps(self):
  89. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 10}):
  90. await self.subject.async_set_percentage(64)
  91. def test_extra_state_attributes(self):
  92. self.assertEqual(self.subject.extra_state_attributes, {})
  93. self.assertEqual(self.timer.extra_state_attributes, {})
  94. def test_timer_options(self):
  95. self.assertCountEqual(
  96. self.timer.options,
  97. [
  98. "cancel",
  99. "30m",
  100. "1h",
  101. "1h30m",
  102. "2h",
  103. "2h30m",
  104. "3h",
  105. "3h30m",
  106. "4h",
  107. "4h30m",
  108. "5h",
  109. "5h30m",
  110. "6h",
  111. "6h30m",
  112. "7h",
  113. "7h30m",
  114. "8h",
  115. "8h30m",
  116. "9h",
  117. "9h30m",
  118. "10h",
  119. ],
  120. )
  121. def test_timer_current_option(self):
  122. self.dps[TIMER_DPS] = "0_5"
  123. self.assertEqual(self.timer.current_option, "30m")
  124. async def test_select_option(self):
  125. async with assert_device_properties_set(
  126. self.timer._device,
  127. {TIMER_DPS: "4_0"},
  128. ):
  129. await self.timer.async_select_option("4h")