test_stirling_fs140dc_fan.py 4.9 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. __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. ),
  27. )
  28. def test_preset_mode(self):
  29. self.dps[PRESET_DPS] = "normal"
  30. self.assertEqual(self.subject.preset_mode, "normal")
  31. self.dps[PRESET_DPS] = "nature"
  32. self.assertEqual(self.subject.preset_mode, "nature")
  33. self.dps[PRESET_DPS] = "sleep"
  34. self.assertEqual(self.subject.preset_mode, "sleep")
  35. self.dps[PRESET_DPS] = None
  36. self.assertIs(self.subject.preset_mode, None)
  37. def test_preset_modes(self):
  38. self.assertCountEqual(
  39. self.subject.preset_modes,
  40. ["normal", "nature", "sleep"],
  41. )
  42. async def test_set_preset_mode_to_normal(self):
  43. async with assert_device_properties_set(
  44. self.subject._device,
  45. {PRESET_DPS: "normal"},
  46. ):
  47. await self.subject.async_set_preset_mode("normal")
  48. async def test_set_preset_mode_to_nature(self):
  49. async with assert_device_properties_set(
  50. self.subject._device,
  51. {PRESET_DPS: "nature"},
  52. ):
  53. await self.subject.async_set_preset_mode("nature")
  54. async def test_set_preset_mode_to_sleep(self):
  55. async with assert_device_properties_set(
  56. self.subject._device,
  57. {PRESET_DPS: "sleep"},
  58. ):
  59. await self.subject.async_set_preset_mode("sleep")
  60. def test_oscillating(self):
  61. self.dps[OSCILLATE_DPS] = False
  62. self.assertFalse(self.subject.oscillating)
  63. self.dps[OSCILLATE_DPS] = True
  64. self.assertTrue(self.subject.oscillating)
  65. self.dps[OSCILLATE_DPS] = None
  66. self.assertFalse(self.subject.oscillating)
  67. async def test_oscillate_off(self):
  68. async with assert_device_properties_set(
  69. self.subject._device, {OSCILLATE_DPS: False}
  70. ):
  71. await self.subject.async_oscillate(False)
  72. async def test_oscillate_on(self):
  73. async with assert_device_properties_set(
  74. self.subject._device, {OSCILLATE_DPS: True}
  75. ):
  76. await self.subject.async_oscillate(True)
  77. def test_speed(self):
  78. self.dps[SPEED_DPS] = "4"
  79. self.assertAlmostEqual(self.subject.percentage, 26.67, 2)
  80. def test_speed_step(self):
  81. self.assertAlmostEqual(self.subject.percentage_step, 6.67, 2)
  82. self.assertEqual(self.subject.speed_count, 15)
  83. async def test_set_speed(self):
  84. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 5}):
  85. await self.subject.async_set_percentage(33)
  86. async def test_set_speed_snaps(self):
  87. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 10}):
  88. await self.subject.async_set_percentage(64)
  89. def test_extra_state_attributes(self):
  90. self.assertEqual(self.subject.extra_state_attributes, {})
  91. self.assertEqual(self.timer.extra_state_attributes, {})
  92. def test_timer_options(self):
  93. self.assertCountEqual(
  94. self.timer.options,
  95. [
  96. "Off",
  97. "30 minutes",
  98. "1 hour",
  99. "1.5 hours",
  100. "2 hours",
  101. "2.5 hours",
  102. "3 hours",
  103. "3.5 hours",
  104. "4 hours",
  105. "4.5 hours",
  106. "5 hours",
  107. "5.5 hours",
  108. "6 hours",
  109. "6.5 hours",
  110. "7 hours",
  111. "7.5 hours",
  112. "8 hours",
  113. "8.5 hours",
  114. "9 hours",
  115. "9.5 hours",
  116. "10 hours",
  117. ],
  118. )
  119. def test_timer_current_option(self):
  120. self.dps[TIMER_DPS] = "0_5"
  121. self.assertEqual(self.timer.current_option, "30 minutes")
  122. async def test_select_option(self):
  123. async with assert_device_properties_set(
  124. self.timer._device,
  125. {TIMER_DPS: "4_0"},
  126. ):
  127. await self.timer.async_select_option("4 hours")