mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 10:59:40 +00:00
Move AutomationActionType to helpers.trigger (#76790)
This commit is contained in:
@@ -5,7 +5,7 @@ import asyncio
|
||||
from collections.abc import Callable
|
||||
import functools
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import TYPE_CHECKING, Any, Protocol, TypedDict
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@@ -27,6 +27,34 @@ _PLATFORM_ALIASES = {
|
||||
}
|
||||
|
||||
|
||||
class TriggerActionType(Protocol):
|
||||
"""Protocol type for trigger action callback."""
|
||||
|
||||
async def __call__(
|
||||
self,
|
||||
run_variables: dict[str, Any],
|
||||
context: Context | None = None,
|
||||
) -> None:
|
||||
"""Define action callback type."""
|
||||
|
||||
|
||||
class TriggerData(TypedDict):
|
||||
"""Trigger data."""
|
||||
|
||||
id: str
|
||||
idx: str
|
||||
|
||||
|
||||
class TriggerInfo(TypedDict):
|
||||
"""Information about trigger."""
|
||||
|
||||
domain: str
|
||||
name: str
|
||||
home_assistant_start: bool
|
||||
variables: TemplateVarsType
|
||||
trigger_data: TriggerData
|
||||
|
||||
|
||||
async def _async_get_trigger_platform(
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> DeviceAutomationTriggerProtocol:
|
||||
@@ -93,11 +121,6 @@ async def async_initialize_triggers(
|
||||
variables: TemplateVarsType = None,
|
||||
) -> CALLBACK_TYPE | None:
|
||||
"""Initialize triggers."""
|
||||
from homeassistant.components.automation import ( # pylint:disable=[import-outside-toplevel]
|
||||
AutomationTriggerData,
|
||||
AutomationTriggerInfo,
|
||||
)
|
||||
|
||||
triggers = []
|
||||
for idx, conf in enumerate(trigger_config):
|
||||
# Skip triggers that are not enabled
|
||||
@@ -107,8 +130,8 @@ async def async_initialize_triggers(
|
||||
platform = await _async_get_trigger_platform(hass, conf)
|
||||
trigger_id = conf.get(CONF_ID, f"{idx}")
|
||||
trigger_idx = f"{idx}"
|
||||
trigger_data = AutomationTriggerData(id=trigger_id, idx=trigger_idx)
|
||||
info = AutomationTriggerInfo(
|
||||
trigger_data = TriggerData(id=trigger_id, idx=trigger_idx)
|
||||
info = TriggerInfo(
|
||||
domain=domain,
|
||||
name=name,
|
||||
home_assistant_start=home_assistant_start,
|
||||
|
||||
Reference in New Issue
Block a user