Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions homeassistant/components/script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
)
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

Expand Down Expand Up @@ -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)

Expand All @@ -180,15 +181,20 @@ async def reload_service(service: ServiceCall) -> None:
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
)

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
Expand All @@ -202,7 +208,10 @@ async def turn_off_service(service: ServiceCall) -> None:

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(
Expand Down