Add trigger door.closed (#165057)

This commit is contained in:
Erik Montnemery
2026-03-07 13:18:46 +00:00
committed by GitHub
parent 71b420b433
commit 281f439bc9
5 changed files with 116 additions and 1 deletions
+3
View File
@@ -1,5 +1,8 @@
{
"triggers": {
"closed": {
"trigger": "mdi:door-closed"
},
"opened": {
"trigger": "mdi:door-open"
}
@@ -14,6 +14,16 @@
},
"title": "Door",
"triggers": {
"closed": {
"description": "Triggers after one or more doors close.",
"fields": {
"behavior": {
"description": "[%key:component::door::common::trigger_behavior_description%]",
"name": "[%key:component::door::common::trigger_behavior_name%]"
}
},
"name": "Door closed"
},
"opened": {
"description": "Triggers after one or more doors open.",
"fields": {
+9 -1
View File
@@ -2,7 +2,7 @@
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
from homeassistant.components.cover import ATTR_IS_CLOSED, DOMAIN as COVER_DOMAIN
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE, STATE_UNKNOWN
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE, STATE_UNKNOWN
from homeassistant.core import HomeAssistant, State, split_entity_id
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity import get_device_class
@@ -65,8 +65,16 @@ class DoorOpenedTrigger(DoorTriggerBase):
_cover_is_closed_target_value = False
class DoorClosedTrigger(DoorTriggerBase):
"""Trigger for door closed state changes."""
_binary_sensor_target_state = STATE_OFF
_cover_is_closed_target_value = True
TRIGGERS: dict[str, type[Trigger]] = {
"opened": DoorOpenedTrigger,
"closed": DoorClosedTrigger,
}
@@ -10,6 +10,15 @@
- last
- any
closed:
fields: *trigger_common_fields
target:
entity:
- domain: binary_sensor
device_class: door
- domain: cover
device_class: door
opened:
fields: *trigger_common_fields
target:
+85
View File
@@ -42,6 +42,7 @@ async def target_covers(hass: HomeAssistant) -> dict[str, list[str]]:
"trigger_key",
[
"door.opened",
"door.closed",
],
)
async def test_door_triggers_gated_by_labs_flag(
@@ -72,6 +73,13 @@ async def test_door_triggers_gated_by_labs_flag(
additional_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="door.closed",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
],
)
async def test_door_trigger_binary_sensor_behavior_any(
@@ -144,6 +152,24 @@ async def test_door_trigger_binary_sensor_behavior_any(
additional_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="door.closed",
target_states=[
(CoverState.CLOSED, {ATTR_IS_CLOSED: True}),
(CoverState.CLOSING, {ATTR_IS_CLOSED: True}),
],
other_states=[
(CoverState.OPEN, {ATTR_IS_CLOSED: False}),
(CoverState.OPENING, {ATTR_IS_CLOSED: False}),
(CoverState.CLOSED, {ATTR_IS_CLOSED: False}),
],
extra_invalid_states=[
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
],
)
async def test_door_trigger_cover_behavior_any(
@@ -205,6 +231,13 @@ async def test_door_trigger_cover_behavior_any(
additional_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="door.closed",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
],
)
async def test_door_trigger_binary_sensor_behavior_first(
@@ -265,6 +298,13 @@ async def test_door_trigger_binary_sensor_behavior_first(
additional_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="door.closed",
target_states=[STATE_OFF],
other_states=[STATE_ON],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
],
)
async def test_door_trigger_binary_sensor_behavior_last(
@@ -338,6 +378,24 @@ async def test_door_trigger_binary_sensor_behavior_last(
additional_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="door.closed",
target_states=[
(CoverState.CLOSED, {ATTR_IS_CLOSED: True}),
(CoverState.CLOSING, {ATTR_IS_CLOSED: True}),
],
other_states=[
(CoverState.OPEN, {ATTR_IS_CLOSED: False}),
(CoverState.OPENING, {ATTR_IS_CLOSED: False}),
(CoverState.CLOSED, {ATTR_IS_CLOSED: False}),
],
extra_invalid_states=[
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
],
)
async def test_door_trigger_cover_behavior_first(
@@ -409,6 +467,24 @@ async def test_door_trigger_cover_behavior_first(
additional_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
*parametrize_trigger_states(
trigger="door.closed",
target_states=[
(CoverState.CLOSED, {ATTR_IS_CLOSED: True}),
(CoverState.CLOSING, {ATTR_IS_CLOSED: True}),
],
other_states=[
(CoverState.OPEN, {ATTR_IS_CLOSED: False}),
(CoverState.OPENING, {ATTR_IS_CLOSED: False}),
(CoverState.CLOSED, {ATTR_IS_CLOSED: False}),
],
extra_invalid_states=[
(CoverState.OPEN, {ATTR_IS_CLOSED: None}),
(CoverState.OPEN, {}),
],
additional_attributes={ATTR_DEVICE_CLASS: "door"},
trigger_from_none=False,
),
],
)
async def test_door_trigger_cover_behavior_last(
@@ -477,6 +553,15 @@ async def test_door_trigger_cover_behavior_last(
CoverState.OPEN,
False,
),
(
"door.closed",
STATE_ON,
STATE_OFF,
CoverState.OPEN,
False,
CoverState.CLOSED,
True,
),
],
)
async def test_door_trigger_excludes_non_door_device_class(