From 2e0e9cd52e31a68b878ba55dc4dce851bc16f861 Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Wed, 2 Dec 2026 15:15:10 +0100 Subject: [PATCH] Use new discovery schema for Z-Wave door lock door status binary sensor (#196024) --- .../components/zwave_js/binary_sensor.py | 47 ++++++------ .../components/zwave_js/discovery.py | 14 ---- .../components/zwave_js/test_binary_sensor.py | 72 +++++++++++++++++++ 3 files changed, 93 insertions(+), 40 deletions(-) diff --git a/homeassistant/components/zwave_js/binary_sensor.py b/homeassistant/components/zwave_js/binary_sensor.py index 0ac0a66e9968..58bb43f9c36a 100644 --- a/homeassistant/components/zwave_js/binary_sensor.py +++ b/homeassistant/components/zwave_js/binary_sensor.py @@ -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( diff --git a/homeassistant/components/zwave_js/discovery.py b/homeassistant/components/zwave_js/discovery.py index 83328abe5795..3c988afa40fe 100644 --- a/homeassistant/components/zwave_js/discovery.py +++ b/homeassistant/components/zwave_js/discovery.py @@ -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, diff --git a/tests/components/zwave_js/test_binary_sensor.py b/tests/components/zwave_js/test_binary_sensor.py index 50613fb89bf4..66c4d38685cc 100644 --- a/tests/components/zwave_js/test_binary_sensor.py +++ b/tests/components/zwave_js/test_binary_sensor.py @@ -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,