1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-26 10:15:33 +01:00
Files
core/homeassistant/components/stream/diagnostics.py
T
2026-04-30 21:14:48 +02:00

32 lines
962 B
Python

"""Diagnostics for debugging.
The stream component does not have config entries itself, and all diagnostics
information is managed by dependent components (e.g. camera)
"""
from collections import Counter
from typing import Any
class Diagnostics:
"""Holds diagnostics counters and key/values."""
def __init__(self) -> None:
"""Initialize Diagnostics."""
self._counter: Counter = Counter()
self._values: dict[str, Any] = {}
def increment(self, key: str) -> None:
"""Increment a counter for the specified key/event."""
self._counter.update(Counter({key: 1}))
def set_value(self, key: str, value: Any) -> None:
"""Update a key/value pair."""
self._values[key] = value
def as_dict(self) -> dict[str, Any]:
"""Return diagnostics as a debug dictionary."""
result = {k: self._counter[k] for k in self._counter}
result.update(self._values)
return result