mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Use TriggerActionType [w-z] (#76814)
This commit is contained in:
parent
702f8180a6
commit
badbc414fb
@ -10,7 +10,6 @@ from aiowebostv import WebOsClient, WebOsTvPairError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import notify as hass_notify
|
||||
from homeassistant.components.automation import AutomationActionType
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_COMMAND,
|
||||
@ -30,6 +29,7 @@ from homeassistant.core import (
|
||||
)
|
||||
from homeassistant.helpers import config_validation as cv, discovery
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.trigger import TriggerActionType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
@ -181,7 +181,7 @@ class PluggableAction:
|
||||
|
||||
@callback
|
||||
def async_attach(
|
||||
self, action: AutomationActionType, variables: dict[str, Any]
|
||||
self, action: TriggerActionType, variables: dict[str, Any]
|
||||
) -> Callable[[], None]:
|
||||
"""Attach a device trigger for turn on."""
|
||||
|
||||
|
@ -3,10 +3,6 @@ from __future__ import annotations
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.automation import (
|
||||
AutomationActionType,
|
||||
AutomationTriggerInfo,
|
||||
)
|
||||
from homeassistant.components.device_automation import DEVICE_TRIGGER_BASE_SCHEMA
|
||||
from homeassistant.components.device_automation.exceptions import (
|
||||
InvalidDeviceAutomationConfig,
|
||||
@ -14,6 +10,7 @@ from homeassistant.components.device_automation.exceptions import (
|
||||
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from . import trigger
|
||||
@ -75,8 +72,8 @@ async def async_get_triggers(
|
||||
async def async_attach_trigger(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
action: AutomationActionType,
|
||||
automation_info: AutomationTriggerInfo,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
) -> CALLBACK_TYPE:
|
||||
"""Attach a trigger."""
|
||||
if (trigger_type := config[CONF_TYPE]) == TURN_ON_PLATFORM_TYPE:
|
||||
@ -88,7 +85,7 @@ async def async_attach_trigger(
|
||||
hass, trigger_config
|
||||
)
|
||||
return await trigger.async_attach_trigger(
|
||||
hass, trigger_config, action, automation_info
|
||||
hass, trigger_config, action, trigger_info
|
||||
)
|
||||
|
||||
raise HomeAssistantError(f"Unhandled trigger type {trigger_type}")
|
||||
|
@ -3,12 +3,9 @@ from __future__ import annotations
|
||||
|
||||
from typing import cast
|
||||
|
||||
from homeassistant.components.automation import (
|
||||
AutomationActionType,
|
||||
AutomationTriggerInfo,
|
||||
)
|
||||
from homeassistant.const import CONF_PLATFORM
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .triggers import TriggersPlatformModule, turn_on
|
||||
@ -39,8 +36,8 @@ async def async_validate_trigger_config(
|
||||
async def async_attach_trigger(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
action: AutomationActionType,
|
||||
automation_info: AutomationTriggerInfo,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
) -> CALLBACK_TYPE:
|
||||
"""Attach trigger of specified platform."""
|
||||
platform = _get_trigger_platform(config)
|
||||
@ -48,6 +45,6 @@ async def async_attach_trigger(
|
||||
return cast(
|
||||
CALLBACK_TYPE,
|
||||
await getattr(platform, "async_attach_trigger")(
|
||||
hass, config, action, automation_info
|
||||
hass, config, action, trigger_info
|
||||
),
|
||||
)
|
||||
|
@ -3,13 +3,10 @@ from __future__ import annotations
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.automation import (
|
||||
AutomationActionType,
|
||||
AutomationTriggerInfo,
|
||||
)
|
||||
from homeassistant.const import ATTR_DEVICE_ID, ATTR_ENTITY_ID, CONF_PLATFORM
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from ..const import DOMAIN
|
||||
@ -39,8 +36,8 @@ TRIGGER_SCHEMA = vol.All(
|
||||
async def async_attach_trigger(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
action: AutomationActionType,
|
||||
automation_info: AutomationTriggerInfo,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
*,
|
||||
platform_type: str = PLATFORM_TYPE,
|
||||
) -> CALLBACK_TYPE | None:
|
||||
@ -57,7 +54,7 @@ async def async_attach_trigger(
|
||||
}
|
||||
)
|
||||
|
||||
trigger_data = automation_info["trigger_data"]
|
||||
trigger_data = trigger_info["trigger_data"]
|
||||
|
||||
unsubs = []
|
||||
|
||||
|
@ -4,14 +4,11 @@ from __future__ import annotations
|
||||
from pywemo.subscribe import EVENT_TYPE_LONG_PRESS
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.automation import (
|
||||
AutomationActionType,
|
||||
AutomationTriggerInfo,
|
||||
)
|
||||
from homeassistant.components.device_automation import DEVICE_TRIGGER_BASE_SCHEMA
|
||||
from homeassistant.components.homeassistant.triggers import event as event_trigger
|
||||
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN as WEMO_DOMAIN, WEMO_SUBSCRIPTION_EVENT
|
||||
@ -57,8 +54,8 @@ async def async_get_triggers(
|
||||
async def async_attach_trigger(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
action: AutomationActionType,
|
||||
automation_info: AutomationTriggerInfo,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
) -> CALLBACK_TYPE:
|
||||
"""Attach a trigger."""
|
||||
event_config = event_trigger.TRIGGER_SCHEMA(
|
||||
@ -72,5 +69,5 @@ async def async_attach_trigger(
|
||||
}
|
||||
)
|
||||
return await event_trigger.async_attach_trigger(
|
||||
hass, event_config, action, automation_info, platform_type="device"
|
||||
hass, event_config, action, trigger_info, platform_type="device"
|
||||
)
|
||||
|
@ -2,10 +2,6 @@
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.automation import (
|
||||
AutomationActionType,
|
||||
AutomationTriggerInfo,
|
||||
)
|
||||
from homeassistant.components.device_automation import DEVICE_TRIGGER_BASE_SCHEMA
|
||||
from homeassistant.components.device_automation.exceptions import (
|
||||
InvalidDeviceAutomationConfig,
|
||||
@ -14,6 +10,7 @@ from homeassistant.components.homeassistant.triggers import event as event_trigg
|
||||
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError, IntegrationError
|
||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from . import DOMAIN as ZHA_DOMAIN
|
||||
@ -54,8 +51,8 @@ async def async_validate_trigger_config(
|
||||
async def async_attach_trigger(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
action: AutomationActionType,
|
||||
automation_info: AutomationTriggerInfo,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
) -> CALLBACK_TYPE:
|
||||
"""Listen for state changes based on configuration."""
|
||||
trigger_key: tuple[str, str] = (config[CONF_TYPE], config[CONF_SUBTYPE])
|
||||
@ -79,7 +76,7 @@ async def async_attach_trigger(
|
||||
|
||||
event_config = event_trigger.TRIGGER_SCHEMA(event_config)
|
||||
return await event_trigger.async_attach_trigger(
|
||||
hass, event_config, action, automation_info, platform_type="device"
|
||||
hass, event_config, action, trigger_info, platform_type="device"
|
||||
)
|
||||
|
||||
|
||||
|
@ -6,10 +6,6 @@ from typing import Any
|
||||
import voluptuous as vol
|
||||
from zwave_js_server.const import CommandClass
|
||||
|
||||
from homeassistant.components.automation import (
|
||||
AutomationActionType,
|
||||
AutomationTriggerInfo,
|
||||
)
|
||||
from homeassistant.components.device_automation import DEVICE_TRIGGER_BASE_SCHEMA
|
||||
from homeassistant.components.device_automation.exceptions import (
|
||||
InvalidDeviceAutomationConfig,
|
||||
@ -29,6 +25,7 @@ from homeassistant.helpers import (
|
||||
device_registry,
|
||||
entity_registry,
|
||||
)
|
||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from . import trigger
|
||||
@ -366,8 +363,8 @@ async def async_get_triggers(
|
||||
async def async_attach_trigger(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
action: AutomationActionType,
|
||||
automation_info: AutomationTriggerInfo,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
) -> CALLBACK_TYPE:
|
||||
"""Attach a trigger."""
|
||||
trigger_type = config[CONF_TYPE]
|
||||
@ -411,7 +408,7 @@ async def async_attach_trigger(
|
||||
|
||||
event_config = event.TRIGGER_SCHEMA(event_config)
|
||||
return await event.async_attach_trigger(
|
||||
hass, event_config, action, automation_info, platform_type="device"
|
||||
hass, event_config, action, trigger_info, platform_type="device"
|
||||
)
|
||||
|
||||
if trigger_platform == "state":
|
||||
@ -427,7 +424,7 @@ async def async_attach_trigger(
|
||||
|
||||
state_config = await state.async_validate_trigger_config(hass, state_config)
|
||||
return await state.async_attach_trigger(
|
||||
hass, state_config, action, automation_info, platform_type="device"
|
||||
hass, state_config, action, trigger_info, platform_type="device"
|
||||
)
|
||||
|
||||
if trigger_platform == VALUE_UPDATED_PLATFORM_TYPE:
|
||||
@ -451,7 +448,7 @@ async def async_attach_trigger(
|
||||
hass, zwave_js_config
|
||||
)
|
||||
return await trigger.async_attach_trigger(
|
||||
hass, zwave_js_config, action, automation_info
|
||||
hass, zwave_js_config, action, trigger_info
|
||||
)
|
||||
|
||||
raise HomeAssistantError(f"Unhandled trigger type {trigger_type}")
|
||||
|
@ -4,12 +4,9 @@ from __future__ import annotations
|
||||
from types import ModuleType
|
||||
from typing import cast
|
||||
|
||||
from homeassistant.components.automation import (
|
||||
AutomationActionType,
|
||||
AutomationTriggerInfo,
|
||||
)
|
||||
from homeassistant.const import CONF_PLATFORM
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .triggers import event, value_updated
|
||||
@ -45,8 +42,8 @@ async def async_validate_trigger_config(
|
||||
async def async_attach_trigger(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
action: AutomationActionType,
|
||||
automation_info: AutomationTriggerInfo,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
) -> CALLBACK_TYPE:
|
||||
"""Attach trigger of specified platform."""
|
||||
platform = _get_trigger_platform(config)
|
||||
@ -54,6 +51,6 @@ async def async_attach_trigger(
|
||||
return cast(
|
||||
CALLBACK_TYPE,
|
||||
await getattr(platform, "async_attach_trigger")(
|
||||
hass, config, action, automation_info
|
||||
hass, config, action, trigger_info
|
||||
),
|
||||
)
|
||||
|
@ -10,10 +10,6 @@ from zwave_js_server.model.controller import CONTROLLER_EVENT_MODEL_MAP
|
||||
from zwave_js_server.model.driver import DRIVER_EVENT_MODEL_MAP
|
||||
from zwave_js_server.model.node import NODE_EVENT_MODEL_MAP
|
||||
|
||||
from homeassistant.components.automation import (
|
||||
AutomationActionType,
|
||||
AutomationTriggerInfo,
|
||||
)
|
||||
from homeassistant.components.zwave_js.const import (
|
||||
ATTR_CONFIG_ENTRY_ID,
|
||||
ATTR_EVENT,
|
||||
@ -32,6 +28,7 @@ from homeassistant.components.zwave_js.helpers import (
|
||||
from homeassistant.const import ATTR_DEVICE_ID, ATTR_ENTITY_ID, CONF_PLATFORM
|
||||
from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .helpers import async_bypass_dynamic_config_validation
|
||||
@ -136,8 +133,8 @@ async def async_validate_trigger_config(
|
||||
async def async_attach_trigger(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
action: AutomationActionType,
|
||||
automation_info: AutomationTriggerInfo,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
*,
|
||||
platform_type: str = PLATFORM_TYPE,
|
||||
) -> CALLBACK_TYPE:
|
||||
@ -156,7 +153,7 @@ async def async_attach_trigger(
|
||||
unsubs = []
|
||||
job = HassJob(action)
|
||||
|
||||
trigger_data = automation_info["trigger_data"]
|
||||
trigger_data = trigger_info["trigger_data"]
|
||||
|
||||
@callback
|
||||
def async_on_event(event_data: dict, device: dr.DeviceEntry | None = None) -> None:
|
||||
|
@ -7,10 +7,6 @@ import voluptuous as vol
|
||||
from zwave_js_server.const import CommandClass
|
||||
from zwave_js_server.model.value import Value, get_value_id
|
||||
|
||||
from homeassistant.components.automation import (
|
||||
AutomationActionType,
|
||||
AutomationTriggerInfo,
|
||||
)
|
||||
from homeassistant.components.zwave_js.config_validation import VALUE_SCHEMA
|
||||
from homeassistant.components.zwave_js.const import (
|
||||
ATTR_COMMAND_CLASS,
|
||||
@ -34,6 +30,7 @@ from homeassistant.components.zwave_js.helpers import (
|
||||
from homeassistant.const import ATTR_DEVICE_ID, ATTR_ENTITY_ID, CONF_PLATFORM, MATCH_ALL
|
||||
from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .helpers import async_bypass_dynamic_config_validation
|
||||
@ -87,8 +84,8 @@ async def async_validate_trigger_config(
|
||||
async def async_attach_trigger(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
action: AutomationActionType,
|
||||
automation_info: AutomationTriggerInfo,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
*,
|
||||
platform_type: str = PLATFORM_TYPE,
|
||||
) -> CALLBACK_TYPE:
|
||||
@ -108,7 +105,7 @@ async def async_attach_trigger(
|
||||
unsubs = []
|
||||
job = HassJob(action)
|
||||
|
||||
trigger_data = automation_info["trigger_data"]
|
||||
trigger_data = trigger_info["trigger_data"]
|
||||
|
||||
@callback
|
||||
def async_on_value_updated(
|
||||
|
Loading…
x
Reference in New Issue
Block a user