Discard duplicate sonos events (#64722)
* Throttle duplicate Sonos events * Fix test by breaking referencepull/64715/head
parent
490d8e1136
commit
a7982adc73
|
@ -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."""
|
||||
|
|
|
@ -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 <str>:<int>.
|
||||
"""
|
||||
self.variables = copy(self.variables)
|
||||
base, count = self.variables[var_name].split(":")
|
||||
newcount = int(count) + 1
|
||||
self.variables[var_name] = ":".join([base, str(newcount)])
|
||||
|
|
Loading…
Reference in New Issue