Automation trigger info type hint improvements (#55402)
* Make automation trigger info a TypedDict * zwave_js trigger type hint fixes * Remove redundant automation trigger info field presence checks * Use async_initialize_triggers in mqtt and tasmota device_trigger tests
This commit is contained in:
parent
0749e045bb
commit
b10fc89a6b
46 changed files with 344 additions and 210 deletions
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||
|
||||
import asyncio
|
||||
import logging
|
||||
from types import MappingProxyType
|
||||
from typing import Any, Callable
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -11,7 +10,7 @@ import voluptuous as vol
|
|||
from homeassistant.const import CONF_ID, CONF_PLATFORM
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
||||
from homeassistant.loader import IntegrationNotFound, async_get_integration
|
||||
|
||||
_PLATFORM_ALIASES = {
|
||||
|
@ -62,15 +61,9 @@ async def async_initialize_triggers(
|
|||
name: str,
|
||||
log_cb: Callable,
|
||||
home_assistant_start: bool = False,
|
||||
variables: dict[str, Any] | MappingProxyType | None = None,
|
||||
variables: TemplateVarsType = None,
|
||||
) -> CALLBACK_TYPE | None:
|
||||
"""Initialize triggers."""
|
||||
info = {
|
||||
"domain": domain,
|
||||
"name": name,
|
||||
"home_assistant_start": home_assistant_start,
|
||||
"variables": variables,
|
||||
}
|
||||
|
||||
triggers = []
|
||||
for idx, conf in enumerate(trigger_config):
|
||||
|
@ -78,7 +71,13 @@ async def async_initialize_triggers(
|
|||
trigger_id = conf.get(CONF_ID, f"{idx}")
|
||||
trigger_idx = f"{idx}"
|
||||
trigger_data = {"id": trigger_id, "idx": trigger_idx}
|
||||
info = {**info, "trigger_data": trigger_data}
|
||||
info = {
|
||||
"domain": domain,
|
||||
"name": name,
|
||||
"home_assistant_start": home_assistant_start,
|
||||
"variables": variables,
|
||||
"trigger_data": trigger_data,
|
||||
}
|
||||
triggers.append(platform.async_attach_trigger(hass, conf, action, info))
|
||||
|
||||
attach_results = await asyncio.gather(*triggers, return_exceptions=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue