1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00
ha-core/homeassistant/components/stream/diagnostics.py
Allen Porter 41a032e3e3
Add diagnostics to stream's Stream objects (#68020)
* Add diagnostics to stream's Stream objects

Add diagnostics key/value pair to the Stream object. Diagnostics support
in camera integration will be added in a follow up and will access the
diagnostics on the Stream object, similar to the examples in the unit
test.

* Rename to audio/video codec

* Fix test codec names

* Update tests/components/stream/test_worker.py

Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>
2022-03-18 07:40:09 -07:00

34 lines
997 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 __future__ import annotations
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 spcified 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