mirror of
https://github.com/home-assistant/core.git
synced 2025-11-17 23:10:28 +00:00
Compare commits
16 Commits
mqtt-suben
...
door_open_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffe5cc978c | ||
|
|
5156a7fe6d | ||
|
|
427f3692fd | ||
|
|
3e5bf7bfd8 | ||
|
|
0b8afb8d7e | ||
|
|
86df75bb51 | ||
|
|
0d94bae6ea | ||
|
|
36f54b2e5b | ||
|
|
fcc7e58671 | ||
|
|
94ce966e1e | ||
|
|
6a7ea639ce | ||
|
|
483e8a1497 | ||
|
|
5a0b0c2f8f | ||
|
|
d472b079cb | ||
|
|
2dc4d9e8ec | ||
|
|
1dc902c413 |
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
]
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user