test_garage_door_opener.py 3.0 KB

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