mirror of
https://github.com/home-assistant/core.git
synced 2025-08-01 09:38:21 +00:00
Adjust
This commit is contained in:
parent
c2a011b16f
commit
17b3d16a26
@ -256,6 +256,11 @@ async def async_attach_trigger(
|
|||||||
class EventTrigger(Trigger):
|
class EventTrigger(Trigger):
|
||||||
"""Z-Wave JS event trigger."""
|
"""Z-Wave JS event trigger."""
|
||||||
|
|
||||||
|
def __init__(self, hass: HomeAssistant, config: ConfigType) -> None:
|
||||||
|
"""Initialize trigger."""
|
||||||
|
self._config = config
|
||||||
|
self._hass = hass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def async_validate_trigger_config(
|
async def async_validate_trigger_config(
|
||||||
cls, hass: HomeAssistant, config: ConfigType
|
cls, hass: HomeAssistant, config: ConfigType
|
||||||
@ -263,13 +268,12 @@ class EventTrigger(Trigger):
|
|||||||
"""Validate config."""
|
"""Validate config."""
|
||||||
return await async_validate_trigger_config(hass, config)
|
return await async_validate_trigger_config(hass, config)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
cls,
|
self,
|
||||||
hass: HomeAssistant,
|
|
||||||
config: ConfigType,
|
|
||||||
action: TriggerActionType,
|
action: TriggerActionType,
|
||||||
trigger_info: TriggerInfo,
|
trigger_info: TriggerInfo,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Attach a trigger."""
|
"""Attach a trigger."""
|
||||||
return await async_attach_trigger(hass, config, action, trigger_info)
|
return await async_attach_trigger(
|
||||||
|
self._hass, self._config, action, trigger_info
|
||||||
|
)
|
||||||
|
@ -207,6 +207,11 @@ async def async_attach_trigger(
|
|||||||
class ValueUpdatedTrigger(Trigger):
|
class ValueUpdatedTrigger(Trigger):
|
||||||
"""Z-Wave JS value updated trigger."""
|
"""Z-Wave JS value updated trigger."""
|
||||||
|
|
||||||
|
def __init__(self, hass: HomeAssistant, config: ConfigType) -> None:
|
||||||
|
"""Initialize trigger."""
|
||||||
|
self._config = config
|
||||||
|
self._hass = hass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def async_validate_trigger_config(
|
async def async_validate_trigger_config(
|
||||||
cls, hass: HomeAssistant, config: ConfigType
|
cls, hass: HomeAssistant, config: ConfigType
|
||||||
@ -214,13 +219,12 @@ class ValueUpdatedTrigger(Trigger):
|
|||||||
"""Validate config."""
|
"""Validate config."""
|
||||||
return await async_validate_trigger_config(hass, config)
|
return await async_validate_trigger_config(hass, config)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
cls,
|
self,
|
||||||
hass: HomeAssistant,
|
|
||||||
config: ConfigType,
|
|
||||||
action: TriggerActionType,
|
action: TriggerActionType,
|
||||||
trigger_info: TriggerInfo,
|
trigger_info: TriggerInfo,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Attach a trigger."""
|
"""Attach a trigger."""
|
||||||
return await async_attach_trigger(hass, config, action, trigger_info)
|
return await async_attach_trigger(
|
||||||
|
self._hass, self._config, action, trigger_info
|
||||||
|
)
|
||||||
|
@ -53,6 +53,9 @@ DATA_PLUGGABLE_ACTIONS: HassKey[defaultdict[tuple, PluggableActionsEntry]] = Has
|
|||||||
class Trigger(abc.ABC):
|
class Trigger(abc.ABC):
|
||||||
"""Trigger class."""
|
"""Trigger class."""
|
||||||
|
|
||||||
|
def __init__(self, hass: HomeAssistant, config: ConfigType) -> None:
|
||||||
|
"""Initialize trigger."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
async def async_validate_trigger_config(
|
async def async_validate_trigger_config(
|
||||||
@ -60,12 +63,9 @@ class Trigger(abc.ABC):
|
|||||||
) -> ConfigType:
|
) -> ConfigType:
|
||||||
"""Validate config."""
|
"""Validate config."""
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
cls,
|
self,
|
||||||
hass: HomeAssistant,
|
|
||||||
config: ConfigType,
|
|
||||||
action: TriggerActionType,
|
action: TriggerActionType,
|
||||||
trigger_info: TriggerInfo,
|
trigger_info: TriggerInfo,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
@ -370,17 +370,15 @@ async def async_initialize_triggers(
|
|||||||
trigger_data=trigger_data,
|
trigger_data=trigger_data,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
action_wrapper = _trigger_action_wrapper(hass, action, conf)
|
||||||
if hasattr(platform, "async_get_triggers"):
|
if hasattr(platform, "async_get_triggers"):
|
||||||
trigger_descriptors = await platform.async_get_triggers(hass)
|
trigger_descriptors = await platform.async_get_triggers(hass)
|
||||||
attach_fn = trigger_descriptors[conf[CONF_PLATFORM]].async_attach_trigger
|
trigger = trigger_descriptors[conf[CONF_PLATFORM]](hass, conf)
|
||||||
|
coro = trigger.async_attach_trigger(action_wrapper, info)
|
||||||
else:
|
else:
|
||||||
attach_fn = platform.async_attach_trigger
|
coro = platform.async_attach_trigger(hass, conf, action_wrapper, info)
|
||||||
|
|
||||||
triggers.append(
|
triggers.append(create_eager_task(coro))
|
||||||
create_eager_task(
|
|
||||||
attach_fn(hass, conf, _trigger_action_wrapper(hass, action, conf), info)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
attach_results = await asyncio.gather(*triggers, return_exceptions=True)
|
attach_results = await asyncio.gather(*triggers, return_exceptions=True)
|
||||||
removes: list[Callable[[], None]] = []
|
removes: list[Callable[[], None]] = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user