test_kogan_garage_door_opener.py 4.0 KB

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