Compare commits

...

1 Commits

Author SHA1 Message Date
Erik
cb5daaf3fe Proof of concept for implementing triggers in a different domain 2026-01-16 14:02:02 +01:00
5 changed files with 26 additions and 1 deletions

View File

@@ -176,6 +176,9 @@
}
},
"triggers": {
"door.opened": {
"trigger": "mdi:door-open"
},
"occupancy_cleared": {
"trigger": "mdi:home-outline"
},

View File

@@ -332,6 +332,16 @@
},
"title": "Binary sensor",
"triggers": {
"door.opened": {
"description": "Triggers after one or more occupancy doors open.",
"fields": {
"behavior": {
"description": "[%key:component::binary_sensor::common::trigger_behavior_description_occupancy%]",
"name": "[%key:component::binary_sensor::common::trigger_behavior_name%]"
}
},
"name": "Door opened"
},
"occupancy_cleared": {
"description": "Triggers after one or more occupancy sensors stop detecting occupancy.",
"fields": {

View File

@@ -53,6 +53,7 @@ def make_binary_sensor_trigger(
TRIGGERS: dict[str, type[Trigger]] = {
"_door.opened": make_binary_sensor_trigger(BinarySensorDeviceClass.DOOR, STATE_ON),
"occupancy_detected": make_binary_sensor_trigger(
BinarySensorDeviceClass.OCCUPANCY, STATE_ON
),

View File

@@ -23,3 +23,10 @@ occupancy_detected:
entity:
domain: binary_sensor
device_class: occupancy
_door.opened:
fields: *trigger_common_fields
target:
entity:
domain: binary_sensor
device_class: door

View File

@@ -121,7 +121,7 @@ def starts_with_dot(key: str) -> str:
_TRIGGERS_DESCRIPTION_SCHEMA = vol.Schema(
{
vol.Remove(vol.All(str, starts_with_dot)): object,
cv.underscore_slug: vol.Any(None, _TRIGGER_DESCRIPTION_SCHEMA),
str: vol.Any(None, _TRIGGER_DESCRIPTION_SCHEMA),
}
)
@@ -1433,6 +1433,10 @@ async def async_get_all_descriptions(
if (target := yaml_description.get("target")) is not None:
description["target"] = target
prefix, sep, _ = missing_trigger.partition(".")
if sep and domain != prefix:
description["translation_domain"] = domain
new_descriptions_cache[missing_trigger] = description
hass.data[TRIGGER_DESCRIPTION_CACHE] = new_descriptions_cache
return new_descriptions_cache