test_goldair_fan.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. from homeassistant.components.fan import FanEntityFeature
  2. from ..const import FAN_PAYLOAD
  3. from ..helpers import assert_device_properties_set
  4. from ..mixins.light import BasicLightTests
  5. from ..mixins.switch import SwitchableTests
  6. from .base_device_tests import TuyaDeviceTestCase
  7. SWITCH_DPS = "1"
  8. FANMODE_DPS = "2"
  9. PRESET_DPS = "3"
  10. SWING_DPS = "8"
  11. TIMER_DPS = "11"
  12. LIGHT_DPS = "101"
  13. class TestGoldairFan(BasicLightTests, SwitchableTests, TuyaDeviceTestCase):
  14. def setUp(self):
  15. self.setUpForConfig("goldair_fan.yaml", FAN_PAYLOAD)
  16. self.subject = self.entities.get("fan")
  17. self.setUpSwitchable(SWITCH_DPS, self.subject)
  18. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_display"))
  19. self.mark_secondary(["light_display"])
  20. def test_supported_features(self):
  21. self.assertEqual(
  22. self.subject.supported_features,
  23. (
  24. FanEntityFeature.OSCILLATE
  25. | FanEntityFeature.PRESET_MODE
  26. | FanEntityFeature.SET_SPEED
  27. | FanEntityFeature.TURN_ON
  28. | FanEntityFeature.TURN_OFF
  29. ),
  30. )
  31. def test_is_on(self):
  32. self.dps[SWITCH_DPS] = True
  33. self.assertTrue(self.subject.is_on)
  34. self.dps[SWITCH_DPS] = False
  35. self.assertFalse(self.subject.is_on)
  36. async def test_turn_on(self):
  37. async with assert_device_properties_set(
  38. self.subject._device, {SWITCH_DPS: True}
  39. ):
  40. await self.subject.async_turn_on()
  41. async def test_turn_off(self):
  42. async with assert_device_properties_set(
  43. self.subject._device, {SWITCH_DPS: False}
  44. ):
  45. await self.subject.async_turn_off()
  46. def test_preset_mode(self):
  47. self.dps[PRESET_DPS] = "normal"
  48. self.assertEqual(self.subject.preset_mode, "normal")
  49. self.dps[PRESET_DPS] = "nature"
  50. self.assertEqual(self.subject.preset_mode, "nature")
  51. self.dps[PRESET_DPS] = "sleep"
  52. self.assertEqual(self.subject.preset_mode, "sleep")
  53. def test_preset_modes(self):
  54. self.assertCountEqual(self.subject.preset_modes, ["normal", "nature", "sleep"])
  55. async def test_set_preset_mode_to_normal(self):
  56. async with assert_device_properties_set(
  57. self.subject._device,
  58. {PRESET_DPS: "normal"},
  59. ):
  60. await self.subject.async_set_preset_mode("normal")
  61. async def test_set_preset_mode_to_nature(self):
  62. async with assert_device_properties_set(
  63. self.subject._device,
  64. {PRESET_DPS: "nature"},
  65. ):
  66. await self.subject.async_set_preset_mode("nature")
  67. async def test_set_preset_mode_to_sleep(self):
  68. async with assert_device_properties_set(
  69. self.subject._device,
  70. {PRESET_DPS: "sleep"},
  71. ):
  72. await self.subject.async_set_preset_mode("sleep")
  73. def test_swing_mode(self):
  74. self.dps[SWING_DPS] = False
  75. self.assertFalse(self.subject.oscillating)
  76. self.dps[SWING_DPS] = True
  77. self.assertTrue(self.subject.oscillating)
  78. self.dps[SWING_DPS] = None
  79. self.assertFalse(self.subject.oscillating)
  80. async def test_oscillate_off(self):
  81. async with assert_device_properties_set(
  82. self.subject._device, {SWING_DPS: False}
  83. ):
  84. await self.subject.async_oscillate(False)
  85. async def test_oscillate_on(self):
  86. async with assert_device_properties_set(
  87. self.subject._device, {SWING_DPS: True}
  88. ):
  89. await self.subject.async_oscillate(True)
  90. def test_speed(self):
  91. self.dps[PRESET_DPS] = "normal"
  92. self.dps[FANMODE_DPS] = 6
  93. self.assertEqual(self.subject.percentage, 50)
  94. async def test_set_speed_in_normal_mode(self):
  95. self.dps[PRESET_DPS] = "normal"
  96. self.dps[SWITCH_DPS] = True
  97. async with assert_device_properties_set(self.subject._device, {FANMODE_DPS: 3}):
  98. await self.subject.async_set_percentage(25)
  99. async def test_set_speed_in_normal_mode_snaps(self):
  100. self.dps[PRESET_DPS] = "normal"
  101. self.dps[SWITCH_DPS] = True
  102. async with assert_device_properties_set(
  103. self.subject._device, {FANMODE_DPS: 10}
  104. ):
  105. await self.subject.async_set_percentage(80)
  106. async def test_set_speed_in_sleep_mode_while_off_snaps_and_turns_on(self):
  107. self.dps[PRESET_DPS] = "sleep"
  108. self.dps[SWITCH_DPS] = False
  109. async with assert_device_properties_set(
  110. self.subject._device, {FANMODE_DPS: 8, SWITCH_DPS: True}
  111. ):
  112. await self.subject.async_set_percentage(75)
  113. async def test_set_speed_to_zero_turns_off(self):
  114. self.dps[SWITCH_DPS] = True
  115. async with assert_device_properties_set(
  116. self.subject._device, {SWITCH_DPS: False}
  117. ):
  118. await self.subject.async_set_percentage(0)
  119. def test_extra_state_attributes(self):
  120. self.dps[TIMER_DPS] = "5"
  121. self.assertEqual(self.subject.extra_state_attributes, {"timer": "5"})