From 5f0fcb1a701f345e7631ffaa1e0e101c611b387e Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 13 Jan 2022 14:24:58 +0100 Subject: [PATCH] Add setup type hints to script (#64030) Co-authored-by: epenet --- homeassistant/components/script/__init__.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/script/__init__.py b/homeassistant/components/script/__init__.py index 6ae8ba41de5..593e585c4a5 100644 --- a/homeassistant/components/script/__init__.py +++ b/homeassistant/components/script/__init__.py @@ -42,6 +42,7 @@ from homeassistant.helpers.script import ( ) from homeassistant.helpers.service import async_set_service_schema from homeassistant.helpers.trace import trace_get, trace_path +from homeassistant.helpers.typing import ConfigType from homeassistant.loader import bind_hass from homeassistant.util.dt import parse_datetime @@ -160,7 +161,7 @@ def areas_in_script(hass: HomeAssistant, entity_id: str) -> list[str]: return list(script_entity.script.referenced_areas) -async def async_setup(hass, config): +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Load the scripts from the configuration.""" hass.data[DOMAIN] = component = EntityComponent(LOGGER, DOMAIN, hass) @@ -180,7 +181,10 @@ async def async_setup(hass, config): async def turn_on_service(service: ServiceCall) -> None: """Call a service to turn script on.""" variables = service.data.get(ATTR_VARIABLES) - for script_entity in await component.async_extract_from_service(service): + script_entities: list[ScriptEntity] = cast( + list[ScriptEntity], await component.async_extract_from_service(service) + ) + for script_entity in script_entities: await script_entity.async_turn_on( variables=variables, context=service.context, wait=False ) @@ -188,7 +192,9 @@ async def async_setup(hass, config): async def turn_off_service(service: ServiceCall) -> None: """Cancel a script.""" # Stopping a script is ok to be done in parallel - script_entities = await component.async_extract_from_service(service) + script_entities: list[ScriptEntity] = cast( + list[ScriptEntity], await component.async_extract_from_service(service) + ) if not script_entities: return @@ -202,7 +208,10 @@ async def async_setup(hass, config): async def toggle_service(service: ServiceCall) -> None: """Toggle a script.""" - for script_entity in await component.async_extract_from_service(service): + script_entities: list[ScriptEntity] = cast( + list[ScriptEntity], await component.async_extract_from_service(service) + ) + for script_entity in script_entities: await script_entity.async_toggle(context=service.context, wait=False) hass.services.async_register(