mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Use TriggerActionType [a-k] (#76812)
This commit is contained in:
parent
badbc414fb
commit
d8916c3e47
@ -3,10 +3,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import voluptuous as vol
|
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 import DEVICE_TRIGGER_BASE_SCHEMA
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
@ -18,6 +14,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import CALLBACK_TYPE, Event, HassJob, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, Event, HassJob, HomeAssistant, callback
|
||||||
from homeassistant.helpers import config_validation as cv, entity_registry
|
from homeassistant.helpers import config_validation as cv, entity_registry
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import DOMAIN, EVENT_TURN_ON
|
from .const import DOMAIN, EVENT_TURN_ON
|
||||||
@ -57,11 +54,11 @@ async def async_get_triggers(
|
|||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
action: AutomationActionType,
|
action: TriggerActionType,
|
||||||
automation_info: AutomationTriggerInfo,
|
trigger_info: TriggerInfo,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Attach a trigger."""
|
"""Attach a trigger."""
|
||||||
trigger_data = automation_info["trigger_data"]
|
trigger_data = trigger_info["trigger_data"]
|
||||||
job = HassJob(action)
|
job = HassJob(action)
|
||||||
|
|
||||||
if config[CONF_TYPE] == "turn_on":
|
if config[CONF_TYPE] == "turn_on":
|
||||||
|
@ -3,10 +3,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import voluptuous as vol
|
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 import DEVICE_TRIGGER_BASE_SCHEMA
|
||||||
from homeassistant.components.device_automation.exceptions import (
|
from homeassistant.components.device_automation.exceptions import (
|
||||||
InvalidDeviceAutomationConfig,
|
InvalidDeviceAutomationConfig,
|
||||||
@ -22,6 +18,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from . import DOMAIN
|
from . import DOMAIN
|
||||||
@ -668,8 +665,8 @@ async def async_validate_trigger_config(
|
|||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
action: AutomationActionType,
|
action: TriggerActionType,
|
||||||
automation_info: AutomationTriggerInfo,
|
trigger_info: TriggerInfo,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Listen for state changes based on configuration."""
|
"""Listen for state changes based on configuration."""
|
||||||
event_data: dict[str, int | str] = {}
|
event_data: dict[str, int | str] = {}
|
||||||
@ -693,7 +690,7 @@ async def async_attach_trigger(
|
|||||||
|
|
||||||
event_config = event_trigger.TRIGGER_SCHEMA(raw_event_config)
|
event_config = event_trigger.TRIGGER_SCHEMA(raw_event_config)
|
||||||
return await event_trigger.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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,14 +10,11 @@ from aiohomekit.model.services import ServicesTypes
|
|||||||
from aiohomekit.utils import clamp_enum_to_char
|
from aiohomekit.utils import clamp_enum_to_char
|
||||||
import voluptuous as vol
|
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 import DEVICE_TRIGGER_BASE_SCHEMA
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE
|
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE
|
||||||
from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import DOMAIN, KNOWN_DEVICES, TRIGGERS
|
from .const import DOMAIN, KNOWN_DEVICES, TRIGGERS
|
||||||
@ -84,11 +81,11 @@ class TriggerSource:
|
|||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
self,
|
self,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
action: AutomationActionType,
|
action: TriggerActionType,
|
||||||
automation_info: AutomationTriggerInfo,
|
trigger_info: TriggerInfo,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Attach a trigger."""
|
"""Attach a trigger."""
|
||||||
trigger_data = automation_info["trigger_data"]
|
trigger_data = trigger_info["trigger_data"]
|
||||||
job = HassJob(action)
|
job = HassJob(action)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -269,10 +266,10 @@ async def async_get_triggers(
|
|||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
action: AutomationActionType,
|
action: TriggerActionType,
|
||||||
automation_info: AutomationTriggerInfo,
|
trigger_info: TriggerInfo,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Attach a trigger."""
|
"""Attach a trigger."""
|
||||||
device_id = config[CONF_DEVICE_ID]
|
device_id = config[CONF_DEVICE_ID]
|
||||||
device = hass.data[TRIGGERS][device_id]
|
device = hass.data[TRIGGERS][device_id]
|
||||||
return await device.async_attach_trigger(config, action, automation_info)
|
return await device.async_attach_trigger(config, action, trigger_info)
|
||||||
|
@ -24,11 +24,8 @@ from .v2.device_trigger import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from homeassistant.components.automation import (
|
|
||||||
AutomationActionType,
|
|
||||||
AutomationTriggerInfo,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
|
|
||||||
from .bridge import HueBridge
|
from .bridge import HueBridge
|
||||||
|
|
||||||
@ -59,8 +56,8 @@ async def async_validate_trigger_config(
|
|||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
action: AutomationActionType,
|
action: TriggerActionType,
|
||||||
automation_info: AutomationTriggerInfo,
|
trigger_info: TriggerInfo,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Listen for state changes based on configuration."""
|
"""Listen for state changes based on configuration."""
|
||||||
device_id = config[CONF_DEVICE_ID]
|
device_id = config[CONF_DEVICE_ID]
|
||||||
@ -75,10 +72,10 @@ async def async_attach_trigger(
|
|||||||
bridge: HueBridge = hass.data[DOMAIN][conf_entry_id]
|
bridge: HueBridge = hass.data[DOMAIN][conf_entry_id]
|
||||||
if bridge.api_version == 1:
|
if bridge.api_version == 1:
|
||||||
return await async_attach_trigger_v1(
|
return await async_attach_trigger_v1(
|
||||||
bridge, device_entry, config, action, automation_info
|
bridge, device_entry, config, action, trigger_info
|
||||||
)
|
)
|
||||||
return await async_attach_trigger_v2(
|
return await async_attach_trigger_v2(
|
||||||
bridge, device_entry, config, action, automation_info
|
bridge, device_entry, config, action, trigger_info
|
||||||
)
|
)
|
||||||
raise InvalidDeviceAutomationConfig(
|
raise InvalidDeviceAutomationConfig(
|
||||||
f"Device ID {device_id} is not found on any Hue bridge"
|
f"Device ID {device_id} is not found on any Hue bridge"
|
||||||
|
@ -3,10 +3,6 @@ from typing import TYPE_CHECKING
|
|||||||
|
|
||||||
import voluptuous as vol
|
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 import DEVICE_TRIGGER_BASE_SCHEMA
|
||||||
from homeassistant.components.device_automation.exceptions import (
|
from homeassistant.components.device_automation.exceptions import (
|
||||||
InvalidDeviceAutomationConfig,
|
InvalidDeviceAutomationConfig,
|
||||||
@ -22,6 +18,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import CALLBACK_TYPE, callback
|
from homeassistant.core import CALLBACK_TYPE, callback
|
||||||
from homeassistant.helpers.device_registry import DeviceEntry
|
from homeassistant.helpers.device_registry import DeviceEntry
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from ..const import ATTR_HUE_EVENT, CONF_SUBTYPE, DOMAIN
|
from ..const import ATTR_HUE_EVENT, CONF_SUBTYPE, DOMAIN
|
||||||
@ -148,8 +145,8 @@ async def async_attach_trigger(
|
|||||||
bridge: "HueBridge",
|
bridge: "HueBridge",
|
||||||
device_entry: DeviceEntry,
|
device_entry: DeviceEntry,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
action: AutomationActionType,
|
action: TriggerActionType,
|
||||||
automation_info: AutomationTriggerInfo,
|
trigger_info: TriggerInfo,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Listen for state changes based on configuration."""
|
"""Listen for state changes based on configuration."""
|
||||||
hass = bridge.hass
|
hass = bridge.hass
|
||||||
@ -171,7 +168,7 @@ async def async_attach_trigger(
|
|||||||
|
|
||||||
event_config = event_trigger.TRIGGER_SCHEMA(event_config)
|
event_config = event_trigger.TRIGGER_SCHEMA(event_config)
|
||||||
return await event_trigger.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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,10 +29,7 @@ from ..const import ATTR_HUE_EVENT, CONF_SUBTYPE, DOMAIN
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from aiohue.v2 import HueBridgeV2
|
from aiohue.v2 import HueBridgeV2
|
||||||
|
|
||||||
from homeassistant.components.automation import (
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
AutomationActionType,
|
|
||||||
AutomationTriggerInfo,
|
|
||||||
)
|
|
||||||
|
|
||||||
from ..bridge import HueBridge
|
from ..bridge import HueBridge
|
||||||
|
|
||||||
@ -77,8 +74,8 @@ async def async_attach_trigger(
|
|||||||
bridge: "HueBridge",
|
bridge: "HueBridge",
|
||||||
device_entry: DeviceEntry,
|
device_entry: DeviceEntry,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
action: AutomationActionType,
|
action: TriggerActionType,
|
||||||
automation_info: AutomationTriggerInfo,
|
trigger_info: TriggerInfo,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Listen for state changes based on configuration."""
|
"""Listen for state changes based on configuration."""
|
||||||
hass = bridge.hass
|
hass = bridge.hass
|
||||||
@ -94,7 +91,7 @@ async def async_attach_trigger(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
return await event_trigger.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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,10 +3,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import voluptuous as vol
|
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 import DEVICE_TRIGGER_BASE_SCHEMA
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
@ -18,6 +14,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import CALLBACK_TYPE, Event, HassJob, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, Event, HassJob, HomeAssistant, callback
|
||||||
from homeassistant.helpers import config_validation as cv, entity_registry
|
from homeassistant.helpers import config_validation as cv, entity_registry
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import DOMAIN, EVENT_TURN_OFF, EVENT_TURN_ON
|
from .const import DOMAIN, EVENT_TURN_OFF, EVENT_TURN_ON
|
||||||
@ -68,11 +65,11 @@ async def async_get_triggers(
|
|||||||
def _attach_trigger(
|
def _attach_trigger(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
action: AutomationActionType,
|
action: TriggerActionType,
|
||||||
event_type,
|
event_type,
|
||||||
automation_info: AutomationTriggerInfo,
|
trigger_info: TriggerInfo,
|
||||||
):
|
):
|
||||||
trigger_data = automation_info["trigger_data"]
|
trigger_data = trigger_info["trigger_data"]
|
||||||
job = HassJob(action)
|
job = HassJob(action)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -90,14 +87,14 @@ def _attach_trigger(
|
|||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
action: AutomationActionType,
|
action: TriggerActionType,
|
||||||
automation_info: AutomationTriggerInfo,
|
trigger_info: TriggerInfo,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Attach a trigger."""
|
"""Attach a trigger."""
|
||||||
if config[CONF_TYPE] == "turn_on":
|
if config[CONF_TYPE] == "turn_on":
|
||||||
return _attach_trigger(hass, config, action, EVENT_TURN_ON, automation_info)
|
return _attach_trigger(hass, config, action, EVENT_TURN_ON, trigger_info)
|
||||||
|
|
||||||
if config[CONF_TYPE] == "turn_off":
|
if config[CONF_TYPE] == "turn_off":
|
||||||
return _attach_trigger(hass, config, action, EVENT_TURN_OFF, automation_info)
|
return _attach_trigger(hass, config, action, EVENT_TURN_OFF, trigger_info)
|
||||||
|
|
||||||
return lambda: None
|
return lambda: None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user