test_garage_door_opener.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. __test__ = True
  10. def setUp(self):
  11. self.setUpForConfig("garage_door_opener.yaml", SIMPLE_GARAGE_DOOR_PAYLOAD)
  12. self.subject = self.entities["cover_garage"]
  13. def test_device_class_is_garage(self):
  14. self.assertEqual(self.subject.device_class, CoverDeviceClass.GARAGE)
  15. def test_supported_features(self):
  16. self.assertEqual(
  17. self.subject.supported_features,
  18. CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE,
  19. )
  20. def test_current_cover_position(self):
  21. self.dps[OPEN_DPS] = True
  22. self.assertEqual(self.subject.current_cover_position, 100)
  23. self.dps[OPEN_DPS] = False
  24. self.assertEqual(self.subject.current_cover_position, 0)
  25. def test_is_opening(self):
  26. self.dps[SWITCH_DPS] = False
  27. self.dps[OPEN_DPS] = False
  28. self.assertFalse(self.subject.is_opening)
  29. self.dps[OPEN_DPS] = True
  30. self.assertFalse(self.subject.is_opening)
  31. self.dps[SWITCH_DPS] = True
  32. self.assertFalse(self.subject.is_opening)
  33. self.dps[OPEN_DPS] = False
  34. self.assertFalse(self.subject.is_opening)
  35. def test_is_closing(self):
  36. self.dps[SWITCH_DPS] = False
  37. self.dps[OPEN_DPS] = False
  38. self.assertFalse(self.subject.is_closing)
  39. self.dps[OPEN_DPS] = True
  40. self.assertFalse(self.subject.is_closing)
  41. self.dps[SWITCH_DPS] = True
  42. self.assertFalse(self.subject.is_closing)
  43. self.dps[OPEN_DPS] = False
  44. self.assertFalse(self.subject.is_closing)
  45. def test_is_closed(self):
  46. self.dps[SWITCH_DPS] = False
  47. self.dps[OPEN_DPS] = True
  48. self.assertFalse(self.subject.is_closed)
  49. self.dps[OPEN_DPS] = False
  50. self.assertTrue(self.subject.is_closed)
  51. async def test_open_cover(self):
  52. async with assert_device_properties_set(
  53. self.subject._device,
  54. {SWITCH_DPS: True},
  55. ):
  56. await self.subject.async_open_cover()
  57. async def test_close_cover(self):
  58. async with assert_device_properties_set(
  59. self.subject._device,
  60. {SWITCH_DPS: False},
  61. ):
  62. await self.subject.async_close_cover()
  63. async def test_set_cover_position_not_supported(self):
  64. with self.assertRaises(NotImplementedError):
  65. await self.subject.async_set_cover_position(50)
  66. async def test_stop_cover_not_supported(self):
  67. with self.assertRaises(NotImplementedError):
  68. await self.subject.async_stop_cover()
  69. def test_extra_state_attributes(self):
  70. self.assertEqual(self.subject.extra_state_attributes, {})