Discard duplicate sonos events (#64722)

* Throttle duplicate Sonos events

* Fix test by breaking reference
pull/64715/head
jjlawren 2022-01-22 17:40:08 -06:00 committed by GitHub
parent 490d8e1136
commit a7982adc73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -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."""

View File

@ -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)])