1 """Class to track subscription event statistics."""
3 from __future__
import annotations
7 from soco.data_structures_entry
import from_didl_string
8 from soco.events_base
import Event
as SonosEvent, parse_event_xml
10 _LOGGER = logging.getLogger(__name__)
14 """Base class of Sonos statistics."""
16 def __init__(self, zone_name: str, kind: str) ->
None:
17 """Initialize SonosStatistics."""
18 self._stats: dict[str, dict[str, int | float]] = {}
23 """Generate a report for use in diagnostics."""
24 return self._stats.copy()
27 """Log statistics for this speaker."""
29 "%s statistics for %s: %s",
37 """Representation of Sonos activity statistics."""
40 """Initialize ActivityStatistics."""
41 super().
__init__(zone_name,
"Activity")
43 def activity(self, source: str, timestamp: float) ->
None:
44 """Track an activity occurrence."""
45 activity_entry = self._stats.setdefault(source, {
"count": 0})
46 activity_entry[
"count"] += 1
47 activity_entry[
"last_seen"] = timestamp
51 """Representation of Sonos event statistics."""
54 """Initialize EventStatistics."""
57 def receive(self, event: SonosEvent) ->
None:
58 """Mark a received event by subscription type."""
59 stats_entry = self._stats.setdefault(
60 event.service.service_type, {
"received": 0,
"duplicates": 0,
"processed": 0}
62 stats_entry[
"received"] += 1
65 """Mark a duplicate event by subscription type."""
66 self._stats[event.service.service_type][
"duplicates"] += 1
68 def process(self, event: SonosEvent) ->
None:
69 """Mark a fully processed event by subscription type."""
70 self._stats[event.service.service_type][
"processed"] += 1
73 """Generate a report for use in diagnostics."""
74 payload = self._stats.copy()
75 payload[
"soco:from_didl_string"] = from_didl_string.cache_info()
76 payload[
"soco:parse_event_xml"] = parse_event_xml.cache_info()
None activity(self, str source, float timestamp)
None __init__(self, str zone_name)
None __init__(self, str zone_name)
None receive(self, SonosEvent event)
None process(self, SonosEvent event)
None duplicate(self, SonosEvent event)
None __init__(self, str zone_name, str kind)