Use TriggerActionType [core, r-t] (#76807)
This commit is contained in:
parent
af002d9dc4
commit
1ebac6c7ca
6 changed files with 24 additions and 46 deletions
|
@ -3,13 +3,10 @@ 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 toggle_entity
|
from homeassistant.components.device_automation import toggle_entity
|
||||||
from homeassistant.const import CONF_DOMAIN
|
from homeassistant.const import CONF_DOMAIN
|
||||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||||
|
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
|
||||||
|
@ -23,13 +20,11 @@ TRIGGER_SCHEMA = vol.All(
|
||||||
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."""
|
||||||
return await toggle_entity.async_attach_trigger(
|
return await toggle_entity.async_attach_trigger(hass, config, action, trigger_info)
|
||||||
hass, config, action, automation_info
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_get_triggers(
|
async def async_get_triggers(
|
||||||
|
|
|
@ -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.homeassistant.triggers.state import (
|
from homeassistant.components.homeassistant.triggers.state import (
|
||||||
CONF_FOR,
|
CONF_FOR,
|
||||||
|
@ -26,6 +22,7 @@ from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import config_validation as cv, entity_registry
|
from homeassistant.helpers import config_validation as cv, entity_registry
|
||||||
from homeassistant.helpers.entity import get_capability
|
from homeassistant.helpers.entity import get_capability
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import ATTR_OPTIONS, DOMAIN
|
from .const import ATTR_OPTIONS, DOMAIN
|
||||||
|
@ -64,8 +61,8 @@ 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."""
|
||||||
state_config = {
|
state_config = {
|
||||||
|
@ -84,7 +81,7 @@ async def async_attach_trigger(
|
||||||
|
|
||||||
state_config = await async_validate_state_trigger_config(hass, state_config)
|
state_config = await async_validate_state_trigger_config(hass, state_config)
|
||||||
return await async_attach_state_trigger(
|
return await async_attach_state_trigger(
|
||||||
hass, state_config, action, automation_info, platform_type="device"
|
hass, state_config, action, trigger_info, platform_type="device"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
"""Provides device triggers for sensors."""
|
"""Provides device triggers for sensors."""
|
||||||
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,
|
||||||
|
@ -27,6 +23,7 @@ from homeassistant.helpers.entity import (
|
||||||
get_device_class,
|
get_device_class,
|
||||||
get_unit_of_measurement,
|
get_unit_of_measurement,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from . import ATTR_STATE_CLASS, DOMAIN, SensorDeviceClass
|
from . import ATTR_STATE_CLASS, DOMAIN, SensorDeviceClass
|
||||||
|
@ -143,8 +140,8 @@ TRIGGER_SCHEMA = vol.All(
|
||||||
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."""
|
||||||
numeric_state_config = {
|
numeric_state_config = {
|
||||||
|
@ -162,7 +159,7 @@ async def async_attach_trigger(
|
||||||
hass, numeric_state_config
|
hass, numeric_state_config
|
||||||
)
|
)
|
||||||
return await numeric_state_trigger.async_attach_trigger(
|
return await numeric_state_trigger.async_attach_trigger(
|
||||||
hass, numeric_state_config, action, automation_info, platform_type="device"
|
hass, numeric_state_config, action, trigger_info, platform_type="device"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,6 @@ from datetime import timedelta
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.automation import (
|
|
||||||
AutomationActionType,
|
|
||||||
AutomationTriggerInfo,
|
|
||||||
)
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_EVENT,
|
CONF_EVENT,
|
||||||
CONF_OFFSET,
|
CONF_OFFSET,
|
||||||
|
@ -16,6 +12,7 @@ from homeassistant.const import (
|
||||||
from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.event import async_track_sunrise, async_track_sunset
|
from homeassistant.helpers.event import async_track_sunrise, async_track_sunset
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
# mypy: allow-untyped-defs, no-check-untyped-defs
|
# mypy: allow-untyped-defs, no-check-untyped-defs
|
||||||
|
@ -32,11 +29,11 @@ TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
|
||||||
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 events based on configuration."""
|
"""Listen for events based on configuration."""
|
||||||
trigger_data = automation_info["trigger_data"]
|
trigger_data = trigger_info["trigger_data"]
|
||||||
event = config.get(CONF_EVENT)
|
event = config.get(CONF_EVENT)
|
||||||
offset = config.get(CONF_OFFSET)
|
offset = config.get(CONF_OFFSET)
|
||||||
description = event
|
description = event
|
||||||
|
|
|
@ -3,13 +3,10 @@ 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 toggle_entity
|
from homeassistant.components.device_automation import toggle_entity
|
||||||
from homeassistant.const import CONF_DOMAIN
|
from homeassistant.const import CONF_DOMAIN
|
||||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||||
|
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
|
||||||
|
@ -23,13 +20,11 @@ TRIGGER_SCHEMA = vol.All(
|
||||||
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."""
|
||||||
return await toggle_entity.async_attach_trigger(
|
return await toggle_entity.async_attach_trigger(hass, config, action, trigger_info)
|
||||||
hass, config, action, automation_info
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_get_triggers(
|
async def async_get_triggers(
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
"""Support for tag triggers."""
|
"""Support for tag triggers."""
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.automation import (
|
|
||||||
AutomationActionType,
|
|
||||||
AutomationTriggerInfo,
|
|
||||||
)
|
|
||||||
from homeassistant.const import CONF_PLATFORM
|
from homeassistant.const import CONF_PLATFORM
|
||||||
from homeassistant.core import CALLBACK_TYPE, Event, HassJob, HomeAssistant
|
from homeassistant.core import CALLBACK_TYPE, Event, HassJob, HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import DEVICE_ID, DOMAIN, EVENT_TAG_SCANNED, TAG_ID
|
from .const import DEVICE_ID, DOMAIN, EVENT_TAG_SCANNED, TAG_ID
|
||||||
|
@ -24,11 +21,11 @@ TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
|
||||||
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 tag_scanned events based on configuration."""
|
"""Listen for tag_scanned events based on configuration."""
|
||||||
trigger_data = automation_info["trigger_data"]
|
trigger_data = trigger_info["trigger_data"]
|
||||||
tag_ids = set(config[TAG_ID])
|
tag_ids = set(config[TAG_ID])
|
||||||
device_ids = set(config[DEVICE_ID]) if DEVICE_ID in config else None
|
device_ids = set(config[DEVICE_ID]) if DEVICE_ID in config else None
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue