diff --git a/homeassistant/components/zwave_js/binary_sensor.py b/homeassistant/components/zwave_js/binary_sensor.py index 1ce035c313d..fcb62ba9a80 100644 --- a/homeassistant/components/zwave_js/binary_sensor.py +++ b/homeassistant/components/zwave_js/binary_sensor.py @@ -122,6 +122,13 @@ class NewNotificationZWaveJSEntityDescription(BinarySensorEntityDescription): # - Replace water filter # - Sump pump failure + +# This set can be removed once all notification sensors have been migrated +# to use the new discovery schema and we've removed the old discovery code. +MIGRATED_NOTIFICATION_TYPES = { + NotificationType.SMOKE_ALARM, +} + NOTIFICATION_SENSOR_MAPPINGS: tuple[NotificationZWaveJSEntityDescription, ...] = ( NotificationZWaveJSEntityDescription( # NotificationType 2: Carbon Monoxide - State Id's 1 and 2 @@ -402,6 +409,12 @@ async def async_setup_entry( # ensure the notification CC Value is valid as binary sensor if not is_valid_notification_binary_sensor(info): return + if ( + notification_type := info.primary_value.metadata.cc_specific[ + CC_SPECIFIC_NOTIFICATION_TYPE + ] + ) in MIGRATED_NOTIFICATION_TYPES: + return # Get all sensors from Notification CC states for state_key in info.primary_value.metadata.states: if TYPE_CHECKING: @@ -414,12 +427,7 @@ async def async_setup_entry( NotificationZWaveJSEntityDescription | None ) = None for description in NOTIFICATION_SENSOR_MAPPINGS: - if ( - int(description.key) - == info.primary_value.metadata.cc_specific[ - CC_SPECIFIC_NOTIFICATION_TYPE - ] - ) and ( + if (int(description.key) == notification_type) and ( not description.states or int(state_key) in description.states ): notification_description = description diff --git a/tests/components/zwave_js/conftest.py b/tests/components/zwave_js/conftest.py index f60c0169055..1a765288cc1 100644 --- a/tests/components/zwave_js/conftest.py +++ b/tests/components/zwave_js/conftest.py @@ -4,6 +4,7 @@ import asyncio from collections.abc import Generator import copy import io +import logging from typing import Any, cast from unittest.mock import DEFAULT, AsyncMock, MagicMock, patch @@ -925,6 +926,7 @@ async def integration_fixture( hass: HomeAssistant, client: MagicMock, platforms: list[Platform], + caplog: pytest.LogCaptureFixture, ) -> MockConfigEntry: """Set up the zwave_js integration.""" entry = MockConfigEntry( @@ -939,6 +941,11 @@ async def integration_fixture( client.async_send_command.reset_mock() + # Make sure no errors logged during setup. + # Eg. unique id collisions are only logged as errors and not raised, + # and may not cause tests to fail otherwise. + assert not any(record.levelno == logging.ERROR for record in caplog.records) + return entry