test_garage_door_opener.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. """Tests for the simple garage door opener."""
  2. from homeassistant.components.cover import (
  3. CoverDeviceClass,
  4. SUPPORT_CLOSE,
  5. SUPPORT_OPEN,
  6. )
  7. from ..const import SIMPLE_GARAGE_DOOR_PAYLOAD
  8. from ..helpers import assert_device_properties_set
  9. from .base_device_tests import TuyaDeviceTestCase
  10. SWITCH_DPS = "1"
  11. OPEN_DPS = "101"
  12. class TestSimpleGarageOpener(TuyaDeviceTestCase):
  13. __test__ = True
  14. def setUp(self):
  15. self.setUpForConfig("garage_door_opener.yaml", SIMPLE_GARAGE_DOOR_PAYLOAD)
  16. self.subject = self.entities["cover"]
  17. def test_device_class_is_garage(self):
  18. self.assertEqual(self.subject.device_class, CoverDeviceClass.GARAGE)
  19. def test_supported_features(self):
  20. self.assertEqual(
  21. self.subject.supported_features,
  22. SUPPORT_OPEN | SUPPORT_CLOSE,
  23. )
  24. def test_current_cover_position(self):
  25. self.dps[OPEN_DPS] = True
  26. self.assertEqual(self.subject.current_cover_position, 100)
  27. self.dps[OPEN_DPS] = False
  28. self.assertEqual(self.subject.current_cover_position, 0)
  29. def test_is_opening(self):
  30. self.dps[SWITCH_DPS] = False
  31. self.dps[OPEN_DPS] = False
  32. self.assertFalse(self.subject.is_opening)
  33. self.dps[OPEN_DPS] = True
  34. self.assertFalse(self.subject.is_opening)
  35. self.dps[SWITCH_DPS] = True
  36. self.assertFalse(self.subject.is_opening)
  37. self.dps[OPEN_DPS] = False
  38. self.assertTrue(self.subject.is_opening)
  39. def test_is_closing(self):
  40. self.dps[SWITCH_DPS] = False
  41. self.dps[OPEN_DPS] = False
  42. self.assertFalse(self.subject.is_closing)
  43. self.dps[OPEN_DPS] = True
  44. self.assertTrue(self.subject.is_closing)
  45. self.dps[SWITCH_DPS] = True
  46. self.assertFalse(self.subject.is_closing)
  47. self.dps[OPEN_DPS] = False
  48. self.assertFalse(self.subject.is_closing)
  49. def test_is_closed(self):
  50. self.dps[OPEN_DPS] = True
  51. self.assertFalse(self.subject.is_closed)
  52. self.dps[OPEN_DPS] = False
  53. self.assertTrue(self.subject.is_closed)
  54. async def test_open_cover(self):
  55. async with assert_device_properties_set(
  56. self.subject._device,
  57. {SWITCH_DPS: True},
  58. ):
  59. await self.subject.async_open_cover()
  60. async def test_close_cover(self):
  61. async with assert_device_properties_set(
  62. self.subject._device,
  63. {SWITCH_DPS: False},
  64. ):
  65. await self.subject.async_close_cover()
  66. async def test_set_cover_position_not_supported(self):
  67. with self.assertRaises(NotImplementedError):
  68. await self.subject.async_set_cover_position(50)
  69. async def test_stop_cover_not_supported(self):
  70. with self.assertRaises(NotImplementedError):
  71. await self.subject.async_stop_cover()
  72. def test_extra_state_attributes(self):
  73. self.assertEqual(self.subject.extra_state_attributes, {})