mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 23:37:18 +00:00
Use TriggerActionType [l-t] (#76813)
This commit is contained in:
parent
223ea03492
commit
702f8180a6
@ -3,15 +3,12 @@ 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 import event
|
from homeassistant.components.homeassistant.triggers import event
|
||||||
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, HomeAssistant
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
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 homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import DOMAIN, KEY_ACTIONS, SENDKEYS
|
from .const import DOMAIN, KEY_ACTIONS, SENDKEYS
|
||||||
@ -75,8 +72,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."""
|
||||||
event_data = {
|
event_data = {
|
||||||
@ -97,7 +94,7 @@ async def async_attach_trigger(
|
|||||||
)
|
)
|
||||||
|
|
||||||
return await event.async_attach_trigger(
|
return await event.async_attach_trigger(
|
||||||
hass, event_config, action, automation_info, platform_type="device"
|
hass, event_config, action, trigger_info, platform_type="device"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,14 +5,11 @@ from collections.abc import Callable
|
|||||||
|
|
||||||
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, 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 track_point_in_utc_time
|
from homeassistant.helpers.event import track_point_in_utc_time
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
@ -39,11 +36,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"]
|
||||||
number = config.get(CONF_NUMBER)
|
number = config.get(CONF_NUMBER)
|
||||||
held_more_than = config.get(CONF_HELD_MORE_THAN)
|
held_more_than = config.get(CONF_HELD_MORE_THAN)
|
||||||
held_less_than = config.get(CONF_HELD_LESS_THAN)
|
held_less_than = config.get(CONF_HELD_LESS_THAN)
|
||||||
|
@ -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.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
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 .const import (
|
from .const import (
|
||||||
@ -425,8 +422,8 @@ def _device_model_to_type(model: str) -> str:
|
|||||||
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_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
@ -453,7 +450,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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 DeviceNotFound
|
from homeassistant.components.device_automation.exceptions import DeviceNotFound
|
||||||
from homeassistant.components.homeassistant.triggers import event as event_trigger
|
from homeassistant.components.homeassistant.triggers import event as event_trigger
|
||||||
@ -19,6 +15,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 .const import DOMAIN, NANOLEAF_EVENT, TOUCH_GESTURE_TRIGGER_MAP, TOUCH_MODELS
|
from .const import DOMAIN, NANOLEAF_EVENT, TOUCH_GESTURE_TRIGGER_MAP, TOUCH_MODELS
|
||||||
@ -58,8 +55,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."""
|
||||||
event_config = event_trigger.TRIGGER_SCHEMA(
|
event_config = event_trigger.TRIGGER_SCHEMA(
|
||||||
@ -73,5 +70,5 @@ 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.components.device_automation.exceptions import (
|
from homeassistant.components.device_automation.exceptions import (
|
||||||
InvalidDeviceAutomationConfig,
|
InvalidDeviceAutomationConfig,
|
||||||
@ -14,6 +10,7 @@ from homeassistant.components.device_automation.exceptions import (
|
|||||||
from homeassistant.components.homeassistant.triggers import event as event_trigger
|
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.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE
|
||||||
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 .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -57,8 +54,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."""
|
||||||
event_config = event_trigger.TRIGGER_SCHEMA(
|
event_config = event_trigger.TRIGGER_SCHEMA(
|
||||||
@ -72,5 +69,5 @@ 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.components.device_automation.exceptions import (
|
from homeassistant.components.device_automation.exceptions import (
|
||||||
InvalidDeviceAutomationConfig,
|
InvalidDeviceAutomationConfig,
|
||||||
@ -26,6 +22,7 @@ from homeassistant.helpers import (
|
|||||||
device_registry as dr,
|
device_registry as dr,
|
||||||
entity_registry,
|
entity_registry,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .climate import STATE_NETATMO_AWAY, STATE_NETATMO_HG, STATE_NETATMO_SCHEDULE
|
from .climate import STATE_NETATMO_AWAY, STATE_NETATMO_HG, STATE_NETATMO_SCHEDULE
|
||||||
@ -140,8 +137,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."""
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
@ -169,5 +166,5 @@ 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"
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,6 @@ from typing import Any
|
|||||||
from haphilipsjs import ConnectionFailure, PhilipsTV
|
from haphilipsjs import ConnectionFailure, PhilipsTV
|
||||||
from haphilipsjs.typing import SystemType
|
from haphilipsjs.typing import SystemType
|
||||||
|
|
||||||
from homeassistant.components.automation import AutomationActionType
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_API_VERSION,
|
CONF_API_VERSION,
|
||||||
@ -21,6 +20,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import Context, HassJob, HomeAssistant, callback
|
from homeassistant.core import Context, HassJob, HomeAssistant, callback
|
||||||
from homeassistant.helpers.debounce import Debouncer
|
from homeassistant.helpers.debounce import Debouncer
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
from .const import CONF_ALLOW_NOTIFY, CONF_SYSTEM, DOMAIN
|
from .const import CONF_ALLOW_NOTIFY, CONF_SYSTEM, DOMAIN
|
||||||
@ -93,7 +93,7 @@ class PluggableAction:
|
|||||||
return bool(self._actions)
|
return bool(self._actions)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_attach(self, action: AutomationActionType, variables: dict[str, Any]):
|
def async_attach(self, action: TriggerActionType, variables: dict[str, Any]):
|
||||||
"""Attach a device trigger for turn on."""
|
"""Attach a device trigger for turn on."""
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -3,15 +3,12 @@ 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 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, HomeAssistant
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
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 PhilipsTVDataUpdateCoordinator
|
from . import PhilipsTVDataUpdateCoordinator
|
||||||
@ -47,11 +44,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"]
|
||||||
registry: dr.DeviceRegistry = dr.async_get(hass)
|
registry: dr.DeviceRegistry = dr.async_get(hass)
|
||||||
if (trigger_type := config[CONF_TYPE]) == TRIGGER_TYPE_TURN_ON:
|
if (trigger_type := config[CONF_TYPE]) == TRIGGER_TYPE_TURN_ON:
|
||||||
variables = {
|
variables = {
|
||||||
|
@ -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,
|
||||||
@ -20,6 +16,7 @@ from homeassistant.const import (
|
|||||||
CONF_TYPE,
|
CONF_TYPE,
|
||||||
)
|
)
|
||||||
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
|
||||||
@ -91,8 +88,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:
|
||||||
"""Attach a trigger."""
|
"""Attach a trigger."""
|
||||||
config = TRIGGER_SCHEMA(config)
|
config = TRIGGER_SCHEMA(config)
|
||||||
@ -113,5 +110,5 @@ 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"
|
||||||
)
|
)
|
||||||
|
@ -5,10 +5,6 @@ from typing import Final
|
|||||||
|
|
||||||
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,
|
||||||
@ -23,6 +19,7 @@ from homeassistant.const import (
|
|||||||
CONF_TYPE,
|
CONF_TYPE,
|
||||||
)
|
)
|
||||||
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 get_block_device_wrapper, get_rpc_device_wrapper
|
from . import get_block_device_wrapper, get_rpc_device_wrapper
|
||||||
@ -140,8 +137,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."""
|
||||||
event_config = {
|
event_config = {
|
||||||
@ -156,5 +153,5 @@ 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"
|
||||||
)
|
)
|
||||||
|
@ -9,10 +9,6 @@ from hatasmota.models import DiscoveryHashType
|
|||||||
from hatasmota.trigger import TasmotaTrigger, TasmotaTriggerConfig
|
from hatasmota.trigger import TasmotaTrigger, TasmotaTriggerConfig
|
||||||
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 import event as event_trigger
|
from homeassistant.components.homeassistant.triggers import event as event_trigger
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -22,6 +18,7 @@ from homeassistant.exceptions import HomeAssistantError
|
|||||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import DOMAIN, TASMOTA_EVENT
|
from .const import DOMAIN, TASMOTA_EVENT
|
||||||
@ -51,8 +48,8 @@ DEVICE_TRIGGERS = "tasmota_device_triggers"
|
|||||||
class TriggerInstance:
|
class TriggerInstance:
|
||||||
"""Attached trigger settings."""
|
"""Attached trigger settings."""
|
||||||
|
|
||||||
action: AutomationActionType = attr.ib()
|
action: TriggerActionType = attr.ib()
|
||||||
automation_info: AutomationTriggerInfo = attr.ib()
|
trigger_info: TriggerInfo = attr.ib()
|
||||||
trigger: Trigger = attr.ib()
|
trigger: Trigger = attr.ib()
|
||||||
remove: CALLBACK_TYPE | None = attr.ib(default=None)
|
remove: CALLBACK_TYPE | None = attr.ib(default=None)
|
||||||
|
|
||||||
@ -77,7 +74,7 @@ class TriggerInstance:
|
|||||||
self.trigger.hass,
|
self.trigger.hass,
|
||||||
event_config,
|
event_config,
|
||||||
self.action,
|
self.action,
|
||||||
self.automation_info,
|
self.trigger_info,
|
||||||
platform_type="device",
|
platform_type="device",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -96,10 +93,10 @@ class Trigger:
|
|||||||
trigger_instances: list[TriggerInstance] = attr.ib(factory=list)
|
trigger_instances: list[TriggerInstance] = attr.ib(factory=list)
|
||||||
|
|
||||||
async def add_trigger(
|
async def add_trigger(
|
||||||
self, action: AutomationActionType, automation_info: AutomationTriggerInfo
|
self, action: TriggerActionType, trigger_info: TriggerInfo
|
||||||
) -> Callable[[], None]:
|
) -> Callable[[], None]:
|
||||||
"""Add Tasmota trigger."""
|
"""Add Tasmota trigger."""
|
||||||
instance = TriggerInstance(action, automation_info, self)
|
instance = TriggerInstance(action, trigger_info, self)
|
||||||
self.trigger_instances.append(instance)
|
self.trigger_instances.append(instance)
|
||||||
|
|
||||||
if self.tasmota_trigger is not None:
|
if self.tasmota_trigger is not None:
|
||||||
@ -303,8 +300,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 device trigger."""
|
"""Attach a device trigger."""
|
||||||
if DEVICE_TRIGGERS not in hass.data:
|
if DEVICE_TRIGGERS not in hass.data:
|
||||||
@ -325,4 +322,4 @@ async def async_attach_trigger(
|
|||||||
tasmota_trigger=None,
|
tasmota_trigger=None,
|
||||||
)
|
)
|
||||||
trigger: Trigger = device_triggers[discovery_id]
|
trigger: Trigger = device_triggers[discovery_id]
|
||||||
return await trigger.add_trigger(action, automation_info)
|
return await trigger.add_trigger(action, trigger_info)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user