test_anko_fan.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. from homeassistant.components.fan import (
  2. SUPPORT_OSCILLATE,
  3. SUPPORT_PRESET_MODE,
  4. SUPPORT_SET_SPEED,
  5. )
  6. from ..const import ANKO_FAN_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from .base_device_tests import SwitchableTests, 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, 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. def test_supported_features(self):
  21. self.assertEqual(
  22. self.subject.supported_features,
  23. SUPPORT_OSCILLATE | SUPPORT_PRESET_MODE | SUPPORT_SET_SPEED,
  24. )
  25. def test_preset_mode(self):
  26. self.dps[PRESET_DPS] = "normal"
  27. self.assertEqual(self.subject.preset_mode, "normal")
  28. self.dps[PRESET_DPS] = "nature"
  29. self.assertEqual(self.subject.preset_mode, "nature")
  30. self.dps[PRESET_DPS] = "sleep"
  31. self.assertEqual(self.subject.preset_mode, "sleep")
  32. self.dps[PRESET_DPS] = None
  33. self.assertIs(self.subject.preset_mode, None)
  34. def test_preset_modes(self):
  35. self.assertCountEqual(self.subject.preset_modes, ["normal", "nature", "sleep"])
  36. async def test_set_preset_mode_to_normal(self):
  37. async with assert_device_properties_set(
  38. self.subject._device,
  39. {PRESET_DPS: "normal"},
  40. ):
  41. await self.subject.async_set_preset_mode("normal")
  42. async def test_set_preset_mode_to_nature(self):
  43. async with assert_device_properties_set(
  44. self.subject._device,
  45. {PRESET_DPS: "nature"},
  46. ):
  47. await self.subject.async_set_preset_mode("nature")
  48. async def test_set_preset_mode_to_sleep(self):
  49. async with assert_device_properties_set(
  50. self.subject._device,
  51. {PRESET_DPS: "sleep"},
  52. ):
  53. await self.subject.async_set_preset_mode("sleep")
  54. def test_oscillating(self):
  55. self.dps[OSCILLATE_DPS] = "off"
  56. self.assertFalse(self.subject.oscillating)
  57. self.dps[OSCILLATE_DPS] = "auto"
  58. self.assertTrue(self.subject.oscillating)
  59. self.dps[OSCILLATE_DPS] = None
  60. self.assertFalse(self.subject.oscillating)
  61. async def test_oscillate_off(self):
  62. async with assert_device_properties_set(
  63. self.subject._device, {OSCILLATE_DPS: "off"}
  64. ):
  65. await self.subject.async_oscillate(False)
  66. async def test_oscillate_on(self):
  67. async with assert_device_properties_set(
  68. self.subject._device, {OSCILLATE_DPS: "auto"}
  69. ):
  70. await self.subject.async_oscillate(True)
  71. def test_speed(self):
  72. self.dps[PRESET_DPS] = "normal"
  73. self.dps[SPEED_DPS] = "4"
  74. self.assertEqual(self.subject.percentage, 50)
  75. def test_speed_step(self):
  76. self.assertEqual(self.subject.percentage_step, 12.5)
  77. self.assertEqual(self.subject.speed_count, 8)
  78. async def test_set_speed_in_normal_mode(self):
  79. self.dps[PRESET_DPS] = "normal"
  80. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 2}):
  81. await self.subject.async_set_percentage(25)
  82. async def test_set_speed_in_normal_mode_snaps(self):
  83. self.dps[PRESET_DPS] = "normal"
  84. async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 6}):
  85. await self.subject.async_set_percentage(80)
  86. def test_device_state_attributes(self):
  87. self.dps[TIMER_DPS] = "5"
  88. self.assertEqual(self.subject.device_state_attributes, {"timer": 5})