Compare commits

...

16 Commits

Author SHA1 Message Date
Ludovic BOUÉ
ffe5cc978c Rename 'door_opened_events' to 'door_open_events' 2025-11-17 19:28:34 +01:00
Ludovic BOUÉ
5156a7fe6d Update door_lock.json to remove unnecessary fields
Removed redundant values for door lock settings.
2025-11-17 19:09:02 +01:00
Ludovic BOUÉ
427f3692fd Add tests for optional door event sensors 2025-11-17 19:07:47 +01:00
Ludovic BOUÉ
3e5bf7bfd8 Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-17 16:57:34 +01:00
Ludovic BOUÉ
0b8afb8d7e Disable entity registry for door lock events 2025-11-17 16:57:18 +01:00
Ludovic BOUÉ
86df75bb51 Update snapshot 2025-11-14 08:35:15 +00:00
Ludovic BOUÉ
0d94bae6ea Update snapshot 2025-11-14 08:23:32 +00:00
Ludovic BOUÉ
36f54b2e5b Change value of '1/257/65532' in door_lock.json
Updated the value for key '1/257/65532' from 0 to 32.
2025-11-14 09:22:18 +01:00
Ludovic BOUÉ
fcc7e58671 Merge remote-tracking branch 'refs/remotes/origin/door_open_events' into door_open_events 2025-11-14 08:15:51 +00:00
Ludovic BOUÉ
94ce966e1e Refactor door lock event translation keys for consistency 2025-11-14 08:14:09 +00:00
Ludovic BOUÉ
6a7ea639ce Update sensor.py 2025-11-14 08:32:03 +01:00
Ludovic BOUÉ
483e8a1497 Total increasing 2025-11-14 08:31:05 +01:00
Ludovic BOUÉ
5a0b0c2f8f Merge branch 'dev' into door_open_events 2025-11-13 21:07:01 +01:00
Ludovic BOUÉ
d472b079cb Add additional attributes for door lock configuration 2025-11-04 20:14:16 +00:00
Ludovic BOUÉ
2dc4d9e8ec Add icons for door lock open and closed events 2025-11-04 20:07:03 +00:00
Ludovic BOUÉ
1dc902c413 Add Matter sensor support for door lock open and closed events 2025-11-04 19:51:03 +00:00
6 changed files with 250 additions and 0 deletions

View File

@@ -86,6 +86,12 @@
"current_phase": {
"default": "mdi:state-machine"
},
"door_lock_door_closed_events": {
"default": "mdi:door-closed"
},
"door_lock_door_opened_events": {
"default": "mdi:door-open"
},
"esa_opt_out_state": {
"default": "mdi:home-lightning-bolt"
},

View File

@@ -1488,4 +1488,30 @@ DISCOVERY_SCHEMAS = [
entity_class=MatterSensor,
required_attributes=(clusters.ServiceArea.Attributes.EstimatedEndTime,),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
entity_description=MatterSensorEntityDescription(
key="DoorLockDoorOpenEvents",
translation_key="door_open_events",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
state_class=SensorStateClass.TOTAL_INCREASING,
),
entity_class=MatterSensor,
required_attributes=(clusters.DoorLock.Attributes.DoorOpenEvents,),
featuremap_contains=clusters.DoorLock.Bitmaps.Feature.kDoorPositionSensor,
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
entity_description=MatterSensorEntityDescription(
key="DoorLockDoorClosedEvents",
translation_key="door_closed_events",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
state_class=SensorStateClass.TOTAL_INCREASING,
),
entity_class=MatterSensor,
required_attributes=(clusters.DoorLock.Attributes.DoorClosedEvents,),
featuremap_contains=clusters.DoorLock.Bitmaps.Feature.kDoorPositionSensor,
),
]

View File

@@ -365,6 +365,12 @@
"current_phase": {
"name": "Current phase"
},
"door_closed_events": {
"name": "Door closed events"
},
"door_open_events": {
"name": "Door open events"
},
"energy_exported": {
"name": "Energy exported"
},

View File

@@ -195,6 +195,55 @@
'state': 'off',
})
# ---
# name: test_binary_sensors[door_lock][binary_sensor.mock_door_lock_door-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': None,
'entity_id': 'binary_sensor.mock_door_lock_door',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
'original_icon': None,
'original_name': 'Door',
'platform': 'matter',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '00000000000004D2-0000000000000001-MatterNodeDevice-1-LockDoorStateSensor-257-3',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensors[door_lock][binary_sensor.mock_door_lock_door-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'door',
'friendly_name': 'Mock Door Lock Door',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.mock_door_lock_door',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensors[door_lock_with_unbolt][binary_sensor.mock_door_lock_with_unbolt_battery-entry]
EntityRegistryEntrySnapshot({
'aliases': set({

View File

@@ -3235,6 +3235,108 @@
'state': '180.0',
})
# ---
# name: test_sensors[door_lock][sensor.mock_door_lock_door_closed_events-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.mock_door_lock_door_closed_events',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Door closed events',
'platform': 'matter',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'door_closed_events',
'unique_id': '00000000000004D2-0000000000000001-MatterNodeDevice-1-DoorLockDoorClosedEvents-257-5',
'unit_of_measurement': None,
})
# ---
# name: test_sensors[door_lock][sensor.mock_door_lock_door_closed_events-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Mock Door Lock Door closed events',
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'context': <ANY>,
'entity_id': 'sensor.mock_door_lock_door_closed_events',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '1',
})
# ---
# name: test_sensors[door_lock][sensor.mock_door_lock_none-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.mock_door_lock_none',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': None,
'platform': 'matter',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'door_open_events',
'unique_id': '00000000000004D2-0000000000000001-MatterNodeDevice-1-DoorLockDoorOpenEvents-257-4',
'unit_of_measurement': None,
})
# ---
# name: test_sensors[door_lock][sensor.mock_door_lock_none-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Mock Door Lock None',
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'context': <ANY>,
'entity_id': 'sensor.mock_door_lock_none',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '1',
})
# ---
# name: test_sensors[eberle_ute3000][sensor.connected_thermostat_ute_3000_heating_demand-entry]
EntityRegistryEntrySnapshot({
'aliases': set({

View File

@@ -3,6 +3,7 @@
from unittest.mock import MagicMock
from matter_server.client.models.node import MatterNode
from matter_server.common.models import EventType
import pytest
from syrupy.assertion import SnapshotAssertion
@@ -697,3 +698,63 @@ async def test_vacuum_operational_error_sensor(
state = hass.states.get("sensor.mock_vacuum_operational_error")
assert state
assert state.state == "unknown"
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
@pytest.mark.parametrize("node_fixture", ["door_lock"])
async def test_optional_door_event_sensors_from_featuremap(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
matter_client: MagicMock,
matter_node: MatterNode,
) -> None:
"""Test discovery of optional door event sensors in doorlock featuremap."""
entity_id_open = "sensor.mock_door_lock_door_open_events"
entity_id_closed = "sensor.mock_door_lock_door_closed_events"
# Initially, feature map is 0, so sensors should not exist in the entity registry
entity_open = entity_registry.async_get(entity_id_open)
assert entity_open is None
entity_closed = entity_registry.async_get(entity_id_closed)
assert entity_closed is None
# Update the feature map to include the optional door sensor feature (bit 5 = 32)
# and fire a node updated event
set_node_attribute(matter_node, 1, 257, 65532, 32)
await trigger_subscription_callback(
hass, matter_client, event=EventType.NODE_UPDATED, data=matter_node
)
await hass.async_block_till_done()
# This should result in new sensor entities being discovered
state = hass.states.get(entity_id_open)
assert state
assert state.state == "5"
state = hass.states.get(entity_id_closed)
assert state
assert state.state == "3"
# Test updating the sensor values
set_node_attribute(matter_node, 1, 257, 4, 10)
await trigger_subscription_callback(hass, matter_client)
state = hass.states.get(entity_id_open)
assert state
assert state.state == "10"
set_node_attribute(matter_node, 1, 257, 5, 8)
await trigger_subscription_callback(hass, matter_client)
state = hass.states.get(entity_id_closed)
assert state
assert state.state == "8"
# Now test the reverse, by removing the feature from the feature map
set_node_attribute(matter_node, 1, 257, 65532, 0)
await trigger_subscription_callback(
hass, matter_client, data=(matter_node.node_id, "1/257/65532", 0)
)
# Entities should be removed from the entity registry
entity_open = entity_registry.async_get(entity_id_open)
assert entity_open is None
entity_closed = entity_registry.async_get(entity_id_closed)
assert entity_closed is None