From 98135d815872f9d61e26c414afabf8dae8915ff1 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 29 Dec 2021 14:30:55 +0100 Subject: [PATCH] Ensure service calls are typed in homeassistant (#62915) Co-authored-by: epenet --- .../components/homeassistant/__init__.py | 6 +++--- homeassistant/components/homeassistant/scene.py | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/homeassistant/__init__.py b/homeassistant/components/homeassistant/__init__.py index d75358fe62e..a1d3880777e 100644 --- a/homeassistant/components/homeassistant/__init__.py +++ b/homeassistant/components/homeassistant/__init__.py @@ -55,11 +55,11 @@ SHUTDOWN_SERVICES = (SERVICE_HOMEASSISTANT_STOP, SERVICE_HOMEASSISTANT_RESTART) async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # noqa: C901 """Set up general services related to Home Assistant.""" - async def async_save_persistent_states(service): + async def async_save_persistent_states(service: ha.ServiceCall) -> None: """Handle calls to homeassistant.save_persistent_states.""" await restore_state.RestoreStateData.async_save_persistent_states(hass) - async def async_handle_turn_service(service): + async def async_handle_turn_service(service: ha.ServiceCall) -> None: """Handle calls to homeassistant.turn_on/off.""" referenced = async_extract_referenced_entity_ids(hass, service) all_referenced = referenced.referenced | referenced.indirectly_referenced @@ -175,7 +175,7 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no if call.service == SERVICE_HOMEASSISTANT_RESTART: asyncio.create_task(hass.async_stop(RESTART_EXIT_CODE)) - async def async_handle_update_service(call): + async def async_handle_update_service(call: ha.ServiceCall) -> None: """Service handler for updating an entity.""" if call.context.user_id: user = await hass.auth.async_get_user(call.context.user_id) diff --git a/homeassistant/components/homeassistant/scene.py b/homeassistant/components/homeassistant/scene.py index cd5da46a03a..e3a7ff51a4e 100644 --- a/homeassistant/components/homeassistant/scene.py +++ b/homeassistant/components/homeassistant/scene.py @@ -21,7 +21,13 @@ from homeassistant.const import ( STATE_OFF, STATE_ON, ) -from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant, State, callback +from homeassistant.core import ( + DOMAIN as HA_DOMAIN, + HomeAssistant, + ServiceCall, + State, + callback, +) from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import ( config_per_platform, @@ -121,9 +127,9 @@ _LOGGER = logging.getLogger(__name__) class SceneConfig(NamedTuple): """Object for storing scene config.""" - id: str + id: str | None name: str - icon: str + icon: str | None states: dict @@ -197,7 +203,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= SCENE_DOMAIN, SERVICE_RELOAD, reload_config ) - async def apply_service(call): + async def apply_service(call: ServiceCall) -> None: """Apply a scene.""" reproduce_options = {} @@ -225,7 +231,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ), ) - async def create_service(call): + async def create_service(call: ServiceCall) -> None: """Create a scene.""" snapshot = call.data[CONF_SNAPSHOT] entities = call.data[CONF_ENTITIES]