test_stirling_fs140dc_fan.py 4.8 KB

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