Add setup type hints to script (#64030)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-01-13 14:24:58 +01:00 committed by GitHub
parent bb9d4c1e2c
commit 5f0fcb1a70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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(