Use TriggerActionType [core, r-t] (#76807)

This commit is contained in:
Marc Mueller 2022-08-15 17:40:16 +02:00 committed by GitHub
parent af002d9dc4
commit 1ebac6c7ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 46 deletions

View File

@ -3,13 +3,10 @@ from __future__ import annotations
import voluptuous as vol
from homeassistant.components.automation import (
AutomationActionType,
AutomationTriggerInfo,
)
from homeassistant.components.device_automation import toggle_entity
from homeassistant.const import CONF_DOMAIN
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType
from . import DOMAIN
@ -23,13 +20,11 @@ TRIGGER_SCHEMA = vol.All(
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."""
return await toggle_entity.async_attach_trigger(
hass, config, action, automation_info
)
return await toggle_entity.async_attach_trigger(hass, config, action, trigger_info)
async def async_get_triggers(

View File

@ -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.homeassistant.triggers.state import (
CONF_FOR,
@ -26,6 +22,7 @@ from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, entity_registry
from homeassistant.helpers.entity import get_capability
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType
from .const import ATTR_OPTIONS, DOMAIN
@ -64,8 +61,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."""
state_config = {
@ -84,7 +81,7 @@ async def async_attach_trigger(
state_config = await async_validate_state_trigger_config(hass, state_config)
return await async_attach_state_trigger(
hass, state_config, action, automation_info, platform_type="device"
hass, state_config, action, trigger_info, platform_type="device"
)

View File

@ -1,10 +1,6 @@
"""Provides device triggers for sensors."""
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,
@ -27,6 +23,7 @@ from homeassistant.helpers.entity import (
get_device_class,
get_unit_of_measurement,
)
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType
from . import ATTR_STATE_CLASS, DOMAIN, SensorDeviceClass
@ -143,8 +140,8 @@ TRIGGER_SCHEMA = vol.All(
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."""
numeric_state_config = {
@ -162,7 +159,7 @@ async def async_attach_trigger(
hass, numeric_state_config
)
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"
)

View File

@ -3,10 +3,6 @@ from datetime import timedelta
import voluptuous as vol
from homeassistant.components.automation import (
AutomationActionType,
AutomationTriggerInfo,
)
from homeassistant.const import (
CONF_EVENT,
CONF_OFFSET,
@ -16,6 +12,7 @@ from homeassistant.const import (
from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import async_track_sunrise, async_track_sunset
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType
# mypy: allow-untyped-defs, no-check-untyped-defs
@ -32,11 +29,11 @@ TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
async def async_attach_trigger(
hass: HomeAssistant,
config: ConfigType,
action: AutomationActionType,
automation_info: AutomationTriggerInfo,
action: TriggerActionType,
trigger_info: TriggerInfo,
) -> CALLBACK_TYPE:
"""Listen for events based on configuration."""
trigger_data = automation_info["trigger_data"]
trigger_data = trigger_info["trigger_data"]
event = config.get(CONF_EVENT)
offset = config.get(CONF_OFFSET)
description = event

View File

@ -3,13 +3,10 @@ from __future__ import annotations
import voluptuous as vol
from homeassistant.components.automation import (
AutomationActionType,
AutomationTriggerInfo,
)
from homeassistant.components.device_automation import toggle_entity
from homeassistant.const import CONF_DOMAIN
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType
from . import DOMAIN
@ -23,13 +20,11 @@ TRIGGER_SCHEMA = vol.All(
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."""
return await toggle_entity.async_attach_trigger(
hass, config, action, automation_info
)
return await toggle_entity.async_attach_trigger(hass, config, action, trigger_info)
async def async_get_triggers(

View File

@ -1,13 +1,10 @@
"""Support for tag triggers."""
import voluptuous as vol
from homeassistant.components.automation import (
AutomationActionType,
AutomationTriggerInfo,
)
from homeassistant.const import CONF_PLATFORM
from homeassistant.core import CALLBACK_TYPE, Event, HassJob, HomeAssistant
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType
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(
hass: HomeAssistant,
config: ConfigType,
action: AutomationActionType,
automation_info: AutomationTriggerInfo,
action: TriggerActionType,
trigger_info: TriggerInfo,
) -> CALLBACK_TYPE:
"""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])
device_ids = set(config[DEVICE_ID]) if DEVICE_ID in config else None