From 39431c0764c1686c5663f3e71f5b44e2c275a272 Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Sun, 3 May 2020 23:21:12 +0200 Subject: [PATCH] Add required features to cover service registration (#35073) * Fix typing in component service method * Add required features to cover service registration * Fix template cover tilt features * Delint template cover tests --- homeassistant/components/cover/__init__.py | 37 ++++++++++++++-------- homeassistant/components/template/cover.py | 2 +- homeassistant/helpers/entity_component.py | 2 +- tests/components/template/test_cover.py | 4 +-- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/cover/__init__.py b/homeassistant/components/cover/__init__.py index 84494e60c6a..ef17abc8a40 100644 --- a/homeassistant/components/cover/__init__.py +++ b/homeassistant/components/cover/__init__.py @@ -94,10 +94,12 @@ async def async_setup(hass, config): await component.async_setup(config) - component.async_register_entity_service(SERVICE_OPEN_COVER, {}, "async_open_cover") + component.async_register_entity_service( + SERVICE_OPEN_COVER, {}, "async_open_cover", [SUPPORT_OPEN] + ) component.async_register_entity_service( - SERVICE_CLOSE_COVER, {}, "async_close_cover" + SERVICE_CLOSE_COVER, {}, "async_close_cover", [SUPPORT_CLOSE] ) component.async_register_entity_service( @@ -108,22 +110,27 @@ async def async_setup(hass, config): ) }, "async_set_cover_position", - ) - - component.async_register_entity_service(SERVICE_STOP_COVER, {}, "async_stop_cover") - - component.async_register_entity_service(SERVICE_TOGGLE, {}, "async_toggle") - - component.async_register_entity_service( - SERVICE_OPEN_COVER_TILT, {}, "async_open_cover_tilt" + [SUPPORT_SET_POSITION], ) component.async_register_entity_service( - SERVICE_CLOSE_COVER_TILT, {}, "async_close_cover_tilt" + SERVICE_STOP_COVER, {}, "async_stop_cover", [SUPPORT_STOP] ) component.async_register_entity_service( - SERVICE_STOP_COVER_TILT, {}, "async_stop_cover_tilt" + SERVICE_TOGGLE, {}, "async_toggle", [SUPPORT_OPEN | SUPPORT_CLOSE] + ) + + component.async_register_entity_service( + SERVICE_OPEN_COVER_TILT, {}, "async_open_cover_tilt", [SUPPORT_OPEN_TILT] + ) + + component.async_register_entity_service( + SERVICE_CLOSE_COVER_TILT, {}, "async_close_cover_tilt", [SUPPORT_CLOSE_TILT] + ) + + component.async_register_entity_service( + SERVICE_STOP_COVER_TILT, {}, "async_stop_cover_tilt", [SUPPORT_STOP_TILT] ) component.async_register_entity_service( @@ -134,10 +141,14 @@ async def async_setup(hass, config): ) }, "async_set_cover_tilt_position", + [SUPPORT_SET_TILT_POSITION], ) component.async_register_entity_service( - SERVICE_TOGGLE_COVER_TILT, {}, "async_toggle_tilt" + SERVICE_TOGGLE_COVER_TILT, + {}, + "async_toggle_tilt", + [SUPPORT_OPEN_TILT | SUPPORT_CLOSE_TILT], ) return True diff --git a/homeassistant/components/template/cover.py b/homeassistant/components/template/cover.py index cea91ea2963..e8bdebe2f58 100644 --- a/homeassistant/components/template/cover.py +++ b/homeassistant/components/template/cover.py @@ -297,7 +297,7 @@ class CoverTemplate(CoverEntity): if self._position_script is not None: supported_features |= SUPPORT_SET_POSITION - if self.current_cover_tilt_position is not None: + if self._tilt_script is not None: supported_features |= TILT_FEATURES return supported_features diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index 0a7c52f7059..fb7762fb9ae 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -201,7 +201,7 @@ class EntityComponent: name: str, schema: Union[Dict[str, Any], vol.Schema], func: str, - required_features: Optional[int] = None, + required_features: Optional[List[int]] = None, ) -> None: """Register an entity service.""" if isinstance(schema, dict): diff --git a/tests/components/template/test_cover.py b/tests/components/template/test_cover.py index c8caf28ddf6..095393c8acb 100644 --- a/tests/components/template/test_cover.py +++ b/tests/components/template/test_cover.py @@ -30,8 +30,8 @@ _LOGGER = logging.getLogger(__name__) ENTITY_COVER = "cover.test_template_cover" -@pytest.fixture -def calls(hass): +@pytest.fixture(name="calls") +def calls_fixture(hass): """Track calls to a mock service.""" return async_mock_service(hass, "test", "automation")