Discard duplicate sonos events (#64722)
* Throttle duplicate Sonos events * Fix test by breaking reference
This commit is contained in:
parent
490d8e1136
commit
a7982adc73
2 changed files with 9 additions and 3 deletions
|
@ -427,12 +427,16 @@ class SonosSpeaker:
|
||||||
|
|
||||||
self.speaker_activity(f"{event.service.service_type} subscription")
|
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 = self._event_dispatchers[event.service.service_type]
|
||||||
dispatcher(event)
|
dispatcher(event)
|
||||||
|
|
||||||
# Save most recent event variables for diagnostics
|
|
||||||
self._last_event_cache[event.service.service_type] = event.variables
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_dispatch_alarms(self, event: SonosEvent) -> None:
|
def async_dispatch_alarms(self, event: SonosEvent) -> None:
|
||||||
"""Add the soco instance associated with the event to the callback."""
|
"""Add the soco instance associated with the event to the callback."""
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Configuration for Sonos tests."""
|
"""Configuration for Sonos tests."""
|
||||||
|
from copy import copy
|
||||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -36,6 +37,7 @@ class SonosMockEvent:
|
||||||
|
|
||||||
Assumes value has a format of <str>:<int>.
|
Assumes value has a format of <str>:<int>.
|
||||||
"""
|
"""
|
||||||
|
self.variables = copy(self.variables)
|
||||||
base, count = self.variables[var_name].split(":")
|
base, count = self.variables[var_name].split(":")
|
||||||
newcount = int(count) + 1
|
newcount = int(count) + 1
|
||||||
self.variables[var_name] = ":".join([base, str(newcount)])
|
self.variables[var_name] = ":".join([base, str(newcount)])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue