test_anko_fan.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. from homeassistant.components.fan import FanEntityFeature
  2. from homeassistant.components.number import NumberDeviceClass
  3. from homeassistant.const import UnitOfTime
  4. from ..const import ANKO_FAN_PAYLOAD
  5. from ..helpers import assert_device_properties_set
  6. from ..mixins.number import BasicNumberTests
  7. from ..mixins.switch import SwitchableTests
  8. from .base_device_tests import TuyaDeviceTestCase
  9. SWITCH_DPS = "1"
  10. PRESET_DPS = "2"
  11. SPEED_DPS = "3"
  12. OSCILLATE_DPS = "4"
  13. TIMER_DPS = "6"
  14. class TestAnkoFan(SwitchableTests, BasicNumberTests, TuyaDeviceTestCase):
  15. __test__ = True
  16. def setUp(self):
  17. self.setUpForConfig("anko_fan.yaml", ANKO_FAN_PAYLOAD)
  18. self.subject = self.entities["fan"]
  19. self.setUpSwitchable(SWITCH_DPS, self.subject)
  20. self.setUpBasicNumber(
  21. TIMER_DPS,
  22. self.entities.get("number_timer"),
  23. max=9,
  24. device_class=NumberDeviceClass.DURATION,
  25. unit=UnitOfTime.HOURS,
  26. )
  27. self.mark_secondary(["number_timer"])
  28. def test_supported_features(self):
  29. self.assertEqual(
  30. self.subject.supported_features,
  31. FanEntityFeature.OSCILLATE
  32. | FanEntityFeature.PRESET_MODE
  33. | FanEntityFeature.SET_SPEED
  34. | FanEntityFeature.TURN_ON
  35. | FanEntityFeature.TURN_OFF,
  36. )
  37. def test_preset_mode(self):
  38. self.dps[PRESET_DPS] = "normal"
  39. self.assertEqual(self.subject.preset_mode, "normal")
  40. self.dps[PRESET_DPS] = "nature"
  41. self.assertEqual(self.subject.preset_mode, "nature")
  42. self.dps[PRESET_DPS] = "sleep"
  43. self.assertEqual(self.subject.preset_mode, "sleep")
  44. self.dps[PRESET_DPS] = None
  45. self.assertIs(self.subject.preset_mode, None)
  46. def test_preset_modes(self):
  47. self.assertCountEqual(self.subject.preset_modes, ["normal", "nature", "sleep"])
  48. async def test_set_preset_mode_to_normal(self):
  49. async with assert_device_properties_set(
  50. self.subject._device,
  51. {PRESET_DPS: "normal"},
  52. ):
  53. await self.subject.async_set_preset_mode("normal")
  54. async def test_set_preset_mode_to_nature(self):
  55. async with assert_device_properties_set(
  56. self.subject._device,
  57. {PRESET_DPS: "nature"},
  58. ):
  59. await self.subject.async_set_preset_mode("nature")
  60. async def test_set_preset_mode_to_sleep(self):
  61. async with assert_device_properties_set(
  62. self.subject._device,
  63. {PRESET_DPS: "sleep"},
  64. ):
  65. await self.subject.async_set_preset_mode("sleep")
  66. def test_oscillating(self):
  67. self.dps[OSCILLATE_DPS] = "off"
  68. self.assertFalse(self.subject.oscillating)
  69. self.dps[OSCILLATE_DPS] = "auto"
  70. self.assertTrue(self.subject.oscillating)
  71. self.dps[OSCILLATE_DPS] = None
  72. self.assertFalse(self.subject.oscillating)
  73. async def test_oscillate_off(self):
  74. async with assert_device_properties_set(
  75. self.subject._device, {OSCILLATE_DPS: "off"}
  76. ):
  77. await self.subject.async_oscillate(False)
  78. async def test_oscillate_on(self):
  79. async with assert_device_properties_set(
  80. self.subject._device, {OSCILLATE_DPS: "auto"}
  81. ):
  82. await self.subject.async_oscillate(True)
  83. def test_speed(self):
  84. self.dps[PRESET_DPS] = "normal"
  85. self.dps[SPEED_DPS] = "4"
  86. self.assertEqual(self.subject.percentage, 50)
  87. def test_speed_step(self):
  88. self.assertEqual(self.subject.percentage_step, 12.5)
  89. self.assertEqual(self.subject.speed_count, 8)
  90. async def test_set_speed_in_normal_mode(self):
  91. self.dps[PRESET_DPS] = "normal"
  92. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: "2"}):
  93. await self.subject.async_set_percentage(25)
  94. async def test_set_speed_in_normal_mode_snaps(self):
  95. self.dps[PRESET_DPS] = "normal"
  96. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: "6"}):
  97. await self.subject.async_set_percentage(80)
  98. async def test_turn_on_with_params(self):
  99. self.dps[SWITCH_DPS] = False
  100. self.dps[SPEED_DPS] = "1"
  101. self.dps[PRESET_DPS] = "normal"
  102. async with assert_device_properties_set(
  103. self.subject._device,
  104. {SWITCH_DPS: True, SPEED_DPS: "6", PRESET_DPS: "nature"},
  105. ):
  106. await self.subject.async_turn_on(80, "nature")