test_goldair_fan.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. from homeassistant.components.fan import (
  2. FanEntityFeature,
  3. )
  4. from ..const import FAN_PAYLOAD
  5. from ..helpers import assert_device_properties_set
  6. from ..mixins.light import BasicLightTests
  7. from ..mixins.switch import SwitchableTests
  8. from .base_device_tests import TuyaDeviceTestCase
  9. HVACMODE_DPS = "1"
  10. FANMODE_DPS = "2"
  11. PRESET_DPS = "3"
  12. SWING_DPS = "8"
  13. TIMER_DPS = "11"
  14. LIGHT_DPS = "101"
  15. class TestGoldairFan(BasicLightTests, SwitchableTests, TuyaDeviceTestCase):
  16. __test__ = True
  17. def setUp(self):
  18. self.setUpForConfig("goldair_fan.yaml", FAN_PAYLOAD)
  19. self.subject = self.entities.get("fan")
  20. self.setUpSwitchable(HVACMODE_DPS, self.subject)
  21. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_display"))
  22. self.mark_secondary(["light_display"])
  23. def test_supported_features(self):
  24. self.assertEqual(
  25. self.subject.supported_features,
  26. (
  27. FanEntityFeature.OSCILLATE
  28. | FanEntityFeature.PRESET_MODE
  29. | FanEntityFeature.SET_SPEED
  30. ),
  31. )
  32. def test_is_on(self):
  33. self.dps[HVACMODE_DPS] = True
  34. self.assertTrue(self.subject.is_on)
  35. self.dps[HVACMODE_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, {HVACMODE_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, {HVACMODE_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. 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. 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_snaps(self):
  106. self.dps[PRESET_DPS] = "sleep"
  107. async with assert_device_properties_set(self.subject._device, {FANMODE_DPS: 8}):
  108. await self.subject.async_set_percentage(75)
  109. def test_extra_state_attributes(self):
  110. self.dps[TIMER_DPS] = "5"
  111. self.assertEqual(self.subject.extra_state_attributes, {"timer": "5"})
  112. def test_light_icon(self):
  113. self.dps[LIGHT_DPS] = True
  114. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  115. self.dps[LIGHT_DPS] = False
  116. self.assertEqual(self.basicLight.icon, "mdi:led-off")