Fix Z-Wave duplicate notification binary sensors (#151304)

This commit is contained in:
Martin Hjelmare
2025-08-28 20:46:43 +02:00
committed by GitHub
parent b01f93119f
commit f85307d86c
2 changed files with 21 additions and 6 deletions

View File

@@ -122,6 +122,13 @@ class NewNotificationZWaveJSEntityDescription(BinarySensorEntityDescription):
# - Replace water filter # - Replace water filter
# - Sump pump failure # - 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, ...] = ( NOTIFICATION_SENSOR_MAPPINGS: tuple[NotificationZWaveJSEntityDescription, ...] = (
NotificationZWaveJSEntityDescription( NotificationZWaveJSEntityDescription(
# NotificationType 2: Carbon Monoxide - State Id's 1 and 2 # 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 # ensure the notification CC Value is valid as binary sensor
if not is_valid_notification_binary_sensor(info): if not is_valid_notification_binary_sensor(info):
return 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 # Get all sensors from Notification CC states
for state_key in info.primary_value.metadata.states: for state_key in info.primary_value.metadata.states:
if TYPE_CHECKING: if TYPE_CHECKING:
@@ -414,12 +427,7 @@ async def async_setup_entry(
NotificationZWaveJSEntityDescription | None NotificationZWaveJSEntityDescription | None
) = None ) = None
for description in NOTIFICATION_SENSOR_MAPPINGS: for description in NOTIFICATION_SENSOR_MAPPINGS:
if ( if (int(description.key) == notification_type) and (
int(description.key)
== info.primary_value.metadata.cc_specific[
CC_SPECIFIC_NOTIFICATION_TYPE
]
) and (
not description.states or int(state_key) in description.states not description.states or int(state_key) in description.states
): ):
notification_description = description notification_description = description

View File

@@ -4,6 +4,7 @@ import asyncio
from collections.abc import Generator from collections.abc import Generator
import copy import copy
import io import io
import logging
from typing import Any, cast from typing import Any, cast
from unittest.mock import DEFAULT, AsyncMock, MagicMock, patch from unittest.mock import DEFAULT, AsyncMock, MagicMock, patch
@@ -925,6 +926,7 @@ async def integration_fixture(
hass: HomeAssistant, hass: HomeAssistant,
client: MagicMock, client: MagicMock,
platforms: list[Platform], platforms: list[Platform],
caplog: pytest.LogCaptureFixture,
) -> MockConfigEntry: ) -> MockConfigEntry:
"""Set up the zwave_js integration.""" """Set up the zwave_js integration."""
entry = MockConfigEntry( entry = MockConfigEntry(
@@ -939,6 +941,11 @@ async def integration_fixture(
client.async_send_command.reset_mock() 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 return entry