mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Add setup type hints to script (#64030)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
bb9d4c1e2c
commit
5f0fcb1a70
@ -42,6 +42,7 @@ from homeassistant.helpers.script import (
|
|||||||
)
|
)
|
||||||
from homeassistant.helpers.service import async_set_service_schema
|
from homeassistant.helpers.service import async_set_service_schema
|
||||||
from homeassistant.helpers.trace import trace_get, trace_path
|
from homeassistant.helpers.trace import trace_get, trace_path
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
from homeassistant.util.dt import parse_datetime
|
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)
|
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."""
|
"""Load the scripts from the configuration."""
|
||||||
hass.data[DOMAIN] = component = EntityComponent(LOGGER, DOMAIN, hass)
|
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:
|
async def turn_on_service(service: ServiceCall) -> None:
|
||||||
"""Call a service to turn script on."""
|
"""Call a service to turn script on."""
|
||||||
variables = service.data.get(ATTR_VARIABLES)
|
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(
|
await script_entity.async_turn_on(
|
||||||
variables=variables, context=service.context, wait=False
|
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:
|
async def turn_off_service(service: ServiceCall) -> None:
|
||||||
"""Cancel a script."""
|
"""Cancel a script."""
|
||||||
# Stopping a script is ok to be done in parallel
|
# 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:
|
if not script_entities:
|
||||||
return
|
return
|
||||||
@ -202,7 +208,10 @@ async def async_setup(hass, config):
|
|||||||
|
|
||||||
async def toggle_service(service: ServiceCall) -> None:
|
async def toggle_service(service: ServiceCall) -> None:
|
||||||
"""Toggle a script."""
|
"""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)
|
await script_entity.async_toggle(context=service.context, wait=False)
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user