test_anko_fan.py 4.4 KB

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