Expose switch attributes in Prometheus component (#35216)

pull/36393/head
Martin Weinelt 2020-06-02 22:47:49 +02:00 committed by GitHub
parent 61c08e792d
commit acfd907c50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -152,6 +152,20 @@ class PrometheusMetrics:
)
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):
if labels is None:
labels = ["entity", "friendly_name", "domain"]
@ -368,6 +382,8 @@ class PrometheusMetrics:
except ValueError:
pass
self._handle_attributes(state)
def _handle_zwave(self, state):
self._battery(state)