Home Assistant Unofficial Reference 2024.12.1
diagnostics.py
Go to the documentation of this file.
1 """Diagnostics for debugging.
2 
3 The stream component does not have config entries itself, and all diagnostics
4 information is managed by dependent components (e.g. camera)
5 """
6 
7 from __future__ import annotations
8 
9 from collections import Counter
10 from typing import Any
11 
12 
14  """Holds diagnostics counters and key/values."""
15 
16  def __init__(self) -> None:
17  """Initialize Diagnostics."""
18  self._counter: Counter = Counter()
19  self._values: dict[str, Any] = {}
20 
21  def increment(self, key: str) -> None:
22  """Increment a counter for the specified key/event."""
23  self._counter.update(Counter({key: 1}))
24 
25  def set_value(self, key: str, value: Any) -> None:
26  """Update a key/value pair."""
27  self._values[key] = value
28 
29  def as_dict(self) -> dict[str, Any]:
30  """Return diagnostics as a debug dictionary."""
31  result = {k: self._counter[k] for k in self._counter}
32  result.update(self._values)
33  return result
IssData update(pyiss.ISS iss)
Definition: __init__.py:33