diff --git a/homeassistant/components/sonos/speaker.py b/homeassistant/components/sonos/speaker.py index ac5a07f2204..1993ab418c5 100644 --- a/homeassistant/components/sonos/speaker.py +++ b/homeassistant/components/sonos/speaker.py @@ -427,12 +427,16 @@ class SonosSpeaker: self.speaker_activity(f"{event.service.service_type} subscription") + # Skip if this update is an unchanged subset of the previous event + if last_event := self._last_event_cache.get(event.service.service_type): + if event.variables.items() <= last_event.items(): + return + + # Save most recently processed event variables for cache and diagnostics + self._last_event_cache[event.service.service_type] = event.variables dispatcher = self._event_dispatchers[event.service.service_type] dispatcher(event) - # Save most recent event variables for diagnostics - self._last_event_cache[event.service.service_type] = event.variables - @callback def async_dispatch_alarms(self, event: SonosEvent) -> None: """Add the soco instance associated with the event to the callback.""" diff --git a/tests/components/sonos/conftest.py b/tests/components/sonos/conftest.py index 2da2d79ba99..14ad17bec8b 100644 --- a/tests/components/sonos/conftest.py +++ b/tests/components/sonos/conftest.py @@ -1,4 +1,5 @@ """Configuration for Sonos tests.""" +from copy import copy from unittest.mock import AsyncMock, MagicMock, Mock, patch import pytest @@ -36,6 +37,7 @@ class SonosMockEvent: Assumes value has a format of :. """ + self.variables = copy(self.variables) base, count = self.variables[var_name].split(":") newcount = int(count) + 1 self.variables[var_name] = ":".join([base, str(newcount)])