test_goldair_fan.py 5.0 KB

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