Make EntityComponent generic (#78473)
This commit is contained in:
parent
fd05d949cc
commit
996bcbdac6
21 changed files with 53 additions and 50 deletions
|
@ -183,7 +183,7 @@ def scripts_with_blueprint(hass: HomeAssistant, blueprint_path: str) -> list[str
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Load the scripts from the configuration."""
|
||||
hass.data[DOMAIN] = component = EntityComponent(LOGGER, DOMAIN, hass)
|
||||
hass.data[DOMAIN] = component = EntityComponent[ScriptEntity](LOGGER, DOMAIN, hass)
|
||||
|
||||
# Process integration platforms right away since
|
||||
# we will create entities before firing EVENT_COMPONENT_LOADED
|
||||
|
@ -205,9 +205,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
async def turn_on_service(service: ServiceCall) -> None:
|
||||
"""Call a service to turn script on."""
|
||||
variables = service.data.get(ATTR_VARIABLES)
|
||||
script_entities: list[ScriptEntity] = cast(
|
||||
list[ScriptEntity], await component.async_extract_from_service(service)
|
||||
)
|
||||
script_entities = 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
|
||||
|
@ -216,9 +214,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
async def turn_off_service(service: ServiceCall) -> None:
|
||||
"""Cancel a script."""
|
||||
# Stopping a script is ok to be done in parallel
|
||||
script_entities: list[ScriptEntity] = cast(
|
||||
list[ScriptEntity], await component.async_extract_from_service(service)
|
||||
)
|
||||
script_entities = await component.async_extract_from_service(service)
|
||||
|
||||
if not script_entities:
|
||||
return
|
||||
|
@ -232,9 +228,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def toggle_service(service: ServiceCall) -> None:
|
||||
"""Toggle a script."""
|
||||
script_entities: list[ScriptEntity] = cast(
|
||||
list[ScriptEntity], await component.async_extract_from_service(service)
|
||||
)
|
||||
script_entities = await component.async_extract_from_service(service)
|
||||
for script_entity in script_entities:
|
||||
await script_entity.async_toggle(context=service.context, wait=False)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue