test_kogan_garage_door_opener.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. """Tests for the simple garage door opener."""
  2. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  3. from homeassistant.components.cover import (
  4. CoverDeviceClass,
  5. SUPPORT_CLOSE,
  6. SUPPORT_OPEN,
  7. )
  8. from homeassistant.components.sensor import SensorDeviceClass
  9. from ..const import KOGAN_GARAGE_DOOR_PAYLOAD
  10. from ..helpers import assert_device_properties_set
  11. from ..mixins.binary_sensor import BasicBinarySensorTests
  12. from ..mixins.sensor import BasicSensorTests
  13. from .base_device_tests import TuyaDeviceTestCase
  14. CONTROL_DPS = "101"
  15. ACTION_DPS = "102"
  16. BATTERY_DPS = "104"
  17. LEFTOPEN_DPS = "105"
  18. class TestKoganGarageOpener(
  19. BasicBinarySensorTests,
  20. BasicSensorTests,
  21. TuyaDeviceTestCase,
  22. ):
  23. __test__ = True
  24. def setUp(self):
  25. self.setUpForConfig("kogan_garage_opener.yaml", KOGAN_GARAGE_DOOR_PAYLOAD)
  26. self.subject = self.entities["cover"]
  27. self.setUpBasicBinarySensor(
  28. LEFTOPEN_DPS,
  29. self.entities.get("binary_sensor_door_open"),
  30. device_class=BinarySensorDeviceClass.GARAGE_DOOR,
  31. )
  32. self.setUpBasicSensor(
  33. BATTERY_DPS,
  34. self.entities.get("sensor_battery"),
  35. device_class=SensorDeviceClass.BATTERY,
  36. )
  37. self.mark_secondary(["binary_sensor_door_open", "sensor_battery"])
  38. def test_device_class_is_garage(self):
  39. self.assertEqual(self.subject.device_class, CoverDeviceClass.GARAGE)
  40. def test_supported_features(self):
  41. self.assertEqual(
  42. self.subject.supported_features,
  43. SUPPORT_OPEN | SUPPORT_CLOSE,
  44. )
  45. def test_current_cover_position(self):
  46. self.dps[ACTION_DPS] = "opened"
  47. self.dps[CONTROL_DPS] = "fopen"
  48. self.assertEqual(self.subject.current_cover_position, 100)
  49. self.dps[ACTION_DPS] = "closed"
  50. self.dps[CONTROL_DPS] = "fclose"
  51. self.assertEqual(self.subject.current_cover_position, 0)
  52. self.dps[ACTION_DPS] = "closing"
  53. self.assertEqual(self.subject.current_cover_position, 50)
  54. def test_is_opening(self):
  55. self.dps[ACTION_DPS] = "opened"
  56. self.assertFalse(self.subject.is_opening)
  57. self.dps[ACTION_DPS] = "closed"
  58. self.assertFalse(self.subject.is_opening)
  59. self.dps[ACTION_DPS] = "closing"
  60. self.assertFalse(self.subject.is_opening)
  61. self.dps[ACTION_DPS] = "openning"
  62. self.assertTrue(self.subject.is_opening)
  63. def test_is_closing(self):
  64. self.dps[ACTION_DPS] = "opened"
  65. self.assertFalse(self.subject.is_closing)
  66. self.dps[ACTION_DPS] = "closed"
  67. self.assertFalse(self.subject.is_closing)
  68. self.dps[ACTION_DPS] = "openning"
  69. self.assertFalse(self.subject.is_closing)
  70. self.dps[ACTION_DPS] = "closing"
  71. self.assertTrue(self.subject.is_closing)
  72. def test_is_closed(self):
  73. self.dps[CONTROL_DPS] = "fclose"
  74. self.dps[ACTION_DPS] = "closing"
  75. self.assertFalse(self.subject.is_closed)
  76. self.dps[ACTION_DPS] = "closed"
  77. self.assertTrue(self.subject.is_closed)
  78. async def test_open_cover(self):
  79. async with assert_device_properties_set(
  80. self.subject._device,
  81. {CONTROL_DPS: "fopen"},
  82. ):
  83. await self.subject.async_open_cover()
  84. async def test_close_cover(self):
  85. async with assert_device_properties_set(
  86. self.subject._device,
  87. {CONTROL_DPS: "fclose"},
  88. ):
  89. await self.subject.async_close_cover()
  90. async def test_set_cover_position_not_supported(self):
  91. with self.assertRaises(NotImplementedError):
  92. await self.subject.async_set_cover_position(50)
  93. async def test_stop_cover_not_supported(self):
  94. with self.assertRaises(NotImplementedError):
  95. await self.subject.async_stop_cover()
  96. def test_extra_state_attributes(self):
  97. self.assertEqual(self.subject.extra_state_attributes, {})