Use new discovery schema for Z-Wave door lock door status binary sensor (#196024)

This commit is contained in:
Martin Hjelmare
2026-12-02 14:15:10 +00:00
committed by GitHub
parent 5e6b17ac01
commit 2e0e9cd52e
3 changed files with 93 additions and 40 deletions
@@ -256,15 +256,6 @@ MIGRATED_NOTIFICATION_TYPES = {
NotificationType.SIREN,
}
# Mappings for property sensors
PROPERTY_SENSOR_MAPPINGS: dict[str, PropertyZWaveJSEntityDescription] = {
DOOR_STATUS_PROPERTY: PropertyZWaveJSEntityDescription(
key=DOOR_STATUS_PROPERTY,
on_states=("open",),
device_class=BinarySensorDeviceClass.DOOR,
),
}
# This can likely be removed once the legacy notification binary sensor
# discovery path is gone and Opening state is handled only by the dedicated
@@ -521,6 +512,12 @@ async def async_setup_entry(
entity = ZWaveLegacyDoorStateBinarySensor(config_entry, driver, info)
entities.append(entity)
_async_check_legacy_entity_repair(hass, driver, entity)
elif (
isinstance(info, NewZwaveDiscoveryInfo)
and info.entity_class is ZWavePropertyBinarySensor
and isinstance(info.entity_description, PropertyZWaveJSEntityDescription)
):
entities.append(ZWavePropertyBinarySensor(config_entry, driver, info))
elif isinstance(info, NewZwaveDiscoveryInfo):
pass # other entity classes are not migrated yet
elif info.platform_hint == "notification":
@@ -542,20 +539,6 @@ async def async_setup_entry(
entities.append(
ZWaveNotificationBinarySensor(config_entry, driver, info, state_key)
)
elif (
info.platform_hint == "property"
and info.primary_value.property_name
and (
property_description := PROPERTY_SENSOR_MAPPINGS.get(
info.primary_value.property_name
)
)
):
entities.append(
ZWavePropertyBinarySensor(
config_entry, driver, info, property_description
)
)
elif info.platform_hint == "config_parameter":
entities.append(
ZWaveConfigParameterBinarySensor(config_entry, driver, info)
@@ -761,12 +744,10 @@ class ZWavePropertyBinarySensor(ZWaveBaseEntity, BinarySensorEntity):
self,
config_entry: ZwaveJSConfigEntry,
driver: Driver,
info: ZwaveDiscoveryInfo,
description: PropertyZWaveJSEntityDescription,
info: NewZwaveDiscoveryInfo,
) -> None:
"""Initialize a ZWavePropertyBinarySensor entity."""
super().__init__(config_entry, driver, info)
self.entity_description = description
self._attr_name = self.generate_name(include_value_name=True)
@property
@@ -1445,6 +1426,20 @@ DISCOVERY_SCHEMAS: list[NewZWaveDiscoverySchema] = [
),
entity_class=ZWaveBooleanBinarySensor,
),
NewZWaveDiscoverySchema(
platform=Platform.BINARY_SENSOR,
primary_value=ZWaveValueDiscoverySchema(
command_class={CommandClass.LOCK, CommandClass.DOOR_LOCK},
property={DOOR_STATUS_PROPERTY},
type={ValueType.ANY},
),
entity_description=PropertyZWaveJSEntityDescription(
key=DOOR_STATUS_PROPERTY,
on_states=("open",),
device_class=BinarySensorDeviceClass.DOOR,
),
entity_class=ZWavePropertyBinarySensor,
),
NewZWaveDiscoverySchema(
platform=Platform.BINARY_SENSOR,
primary_value=ZWaveValueDiscoverySchema(
@@ -21,7 +21,6 @@ from zwave_js_server.const.command_class.humidity_control import (
)
from zwave_js_server.const.command_class.lock import (
CURRENT_MODE_PROPERTY,
DOOR_STATUS_PROPERTY,
LOCKED_PROPERTY,
)
from zwave_js_server.const.command_class.meter import (
@@ -888,19 +887,6 @@ DISCOVERY_SCHEMAS = [
),
absent_values=[DOOR_LOCK_CURRENT_MODE_SCHEMA],
),
# door lock door status
ZWaveDiscoverySchema(
platform=Platform.BINARY_SENSOR,
hint="property",
primary_value=ZWaveValueDiscoverySchema(
command_class={
CommandClass.LOCK,
CommandClass.DOOR_LOCK,
},
property={DOOR_STATUS_PROPERTY},
type={ValueType.ANY},
),
),
# thermostat fan
ZWaveDiscoverySchema(
platform=Platform.FAN,
@@ -1247,6 +1247,78 @@ async def test_property_sensor_door_status(
assert state.state == STATE_UNKNOWN
@pytest.fixture(name="door_lock_node")
def door_lock_node_fixture(request: pytest.FixtureRequest) -> Node:
"""Load the node fixture named by the test parameter."""
return request.getfixturevalue(request.param)
@pytest.mark.parametrize(
("door_lock_node", "entity_id", "expected_state"),
[
pytest.param(
"lock_august_pro",
PROPERTY_DOOR_STATUS_BINARY_SENSOR,
STATE_OFF,
id="august_asl03",
),
pytest.param(
"lock_schlage_be469",
"binary_sensor.touchscreen_deadbolt_the_current_status_of_the_door",
STATE_ON,
id="schlage_be469",
),
pytest.param(
"lock_id_lock_as_id150",
"binary_sensor.z_wave_module_for_id_lock_150_and_101_the_current_status_of_the_door",
STATE_OFF,
id="id_lock_as_id150",
),
pytest.param(
"lock_popp_electric_strike_lock_control",
"binary_sensor.node_62_the_current_status_of_the_door",
STATE_OFF,
id="popp_electric_strike",
),
pytest.param(
"lock_home_connect_620",
"binary_sensor.shed_door_lock_the_current_status_of_the_door",
STATE_ON,
id="home_connect_620",
),
],
indirect=["door_lock_node"],
)
async def test_door_lock_door_status_sensor(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
door_lock_node: Node,
integration: MockConfigEntry,
entity_id: str,
expected_state: str,
) -> None:
"""Test the Door Lock CC door status binary sensor and its count per node."""
entries = [
entry
for entry in entity_registry.entities.values()
if entry.domain == BINARY_SENSOR_DOMAIN
and f".{door_lock_node.node_id}-98-" in entry.unique_id
]
assert len(entries) == 1
entry = entries[0]
assert entry.entity_id == entity_id
assert entry.unique_id.endswith(f".{door_lock_node.node_id}-98-0-doorStatus")
assert entry.original_device_class == BinarySensorDeviceClass.DOOR
assert entry.entity_category is None
assert entry.disabled_by is None
assert entry.unit_of_measurement is None
state = hass.states.get(entity_id)
assert state
assert state.state == expected_state
assert state.attributes[ATTR_DEVICE_CLASS] == BinarySensorDeviceClass.DOOR
async def test_opening_state_creates_open_binary_sensor(
hass: HomeAssistant,
client,