test_kogan_garage_door_opener.py 4.0 KB

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