test_stirling_fs140dc_fan.py 4.8 KB

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