test_goldair_fan.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. ),
  29. )
  30. def test_is_on(self):
  31. self.dps[SWITCH_DPS] = True
  32. self.assertTrue(self.subject.is_on)
  33. self.dps[SWITCH_DPS] = False
  34. self.assertFalse(self.subject.is_on)
  35. async def test_turn_on(self):
  36. async with assert_device_properties_set(
  37. self.subject._device, {SWITCH_DPS: True}
  38. ):
  39. await self.subject.async_turn_on()
  40. async def test_turn_off(self):
  41. async with assert_device_properties_set(
  42. self.subject._device, {SWITCH_DPS: False}
  43. ):
  44. await self.subject.async_turn_off()
  45. def test_preset_mode(self):
  46. self.dps[PRESET_DPS] = "normal"
  47. self.assertEqual(self.subject.preset_mode, "normal")
  48. self.dps[PRESET_DPS] = "nature"
  49. self.assertEqual(self.subject.preset_mode, "nature")
  50. self.dps[PRESET_DPS] = "sleep"
  51. self.assertEqual(self.subject.preset_mode, "sleep")
  52. def test_preset_modes(self):
  53. self.assertCountEqual(self.subject.preset_modes, ["normal", "nature", "sleep"])
  54. async def test_set_preset_mode_to_normal(self):
  55. async with assert_device_properties_set(
  56. self.subject._device,
  57. {PRESET_DPS: "normal"},
  58. ):
  59. await self.subject.async_set_preset_mode("normal")
  60. async def test_set_preset_mode_to_nature(self):
  61. async with assert_device_properties_set(
  62. self.subject._device,
  63. {PRESET_DPS: "nature"},
  64. ):
  65. await self.subject.async_set_preset_mode("nature")
  66. async def test_set_preset_mode_to_sleep(self):
  67. async with assert_device_properties_set(
  68. self.subject._device,
  69. {PRESET_DPS: "sleep"},
  70. ):
  71. await self.subject.async_set_preset_mode("sleep")
  72. def test_swing_mode(self):
  73. self.dps[SWING_DPS] = False
  74. self.assertFalse(self.subject.oscillating)
  75. self.dps[SWING_DPS] = True
  76. self.assertTrue(self.subject.oscillating)
  77. self.dps[SWING_DPS] = None
  78. self.assertFalse(self.subject.oscillating)
  79. async def test_oscillate_off(self):
  80. async with assert_device_properties_set(
  81. self.subject._device, {SWING_DPS: False}
  82. ):
  83. await self.subject.async_oscillate(False)
  84. async def test_oscillate_on(self):
  85. async with assert_device_properties_set(
  86. self.subject._device, {SWING_DPS: True}
  87. ):
  88. await self.subject.async_oscillate(True)
  89. def test_speed(self):
  90. self.dps[PRESET_DPS] = "normal"
  91. self.dps[FANMODE_DPS] = 6
  92. self.assertEqual(self.subject.percentage, 50)
  93. async def test_set_speed_in_normal_mode(self):
  94. self.dps[PRESET_DPS] = "normal"
  95. self.dps[SWITCH_DPS] = True
  96. async with assert_device_properties_set(self.subject._device, {FANMODE_DPS: 3}):
  97. await self.subject.async_set_percentage(25)
  98. async def test_set_speed_in_normal_mode_snaps(self):
  99. self.dps[PRESET_DPS] = "normal"
  100. self.dps[SWITCH_DPS] = True
  101. async with assert_device_properties_set(
  102. self.subject._device, {FANMODE_DPS: 10}
  103. ):
  104. await self.subject.async_set_percentage(80)
  105. async def test_set_speed_in_sleep_mode_while_off_snaps_and_turns_on(self):
  106. self.dps[PRESET_DPS] = "sleep"
  107. self.dps[SWITCH_DPS] = False
  108. async with assert_device_properties_set(
  109. self.subject._device, {FANMODE_DPS: 8, SWITCH_DPS: True}
  110. ):
  111. await self.subject.async_set_percentage(75)
  112. async def test_set_speed_to_zero_turns_off(self):
  113. self.dps[SWITCH_DPS] = True
  114. async with assert_device_properties_set(
  115. self.subject._device, {SWITCH_DPS: False}
  116. ):
  117. await self.subject.async_set_percentage(0)
  118. def test_extra_state_attributes(self):
  119. self.dps[TIMER_DPS] = "5"
  120. self.assertEqual(self.subject.extra_state_attributes, {"timer": "5"})
  121. def test_light_icon(self):
  122. self.dps[LIGHT_DPS] = True
  123. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  124. self.dps[LIGHT_DPS] = False
  125. self.assertEqual(self.basicLight.icon, "mdi:led-off")