mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 22:07:10 +00:00
Expose switch attributes in Prometheus component (#35216)
This commit is contained in:
parent
61c08e792d
commit
acfd907c50
@ -152,6 +152,20 @@ class PrometheusMetrics:
|
|||||||
)
|
)
|
||||||
metric.labels(**self._labels(state)).inc()
|
metric.labels(**self._labels(state)).inc()
|
||||||
|
|
||||||
|
def _handle_attributes(self, state):
|
||||||
|
for key, value in state.attributes.items():
|
||||||
|
metric = self._metric(
|
||||||
|
f"{state.domain}_attr_{key.lower()}",
|
||||||
|
self.prometheus_cli.Gauge,
|
||||||
|
f"{key} attribute of {state.domain} entity",
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
value = float(value)
|
||||||
|
metric.labels(**self._labels(state)).set(value)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
def _metric(self, metric, factory, documentation, labels=None):
|
def _metric(self, metric, factory, documentation, labels=None):
|
||||||
if labels is None:
|
if labels is None:
|
||||||
labels = ["entity", "friendly_name", "domain"]
|
labels = ["entity", "friendly_name", "domain"]
|
||||||
@ -368,6 +382,8 @@ class PrometheusMetrics:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
self._handle_attributes(state)
|
||||||
|
|
||||||
def _handle_zwave(self, state):
|
def _handle_zwave(self, state):
|
||||||
self._battery(state)
|
self._battery(state)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user