test_garage_door_opener.py 3.0 KB

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