mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add a Prometheus metric for HVAC action (#31945)
This commit is contained in:
parent
37832d5e81
commit
d14112748c
@ -84,6 +84,17 @@ CURRENT_HVAC_IDLE = "idle"
|
|||||||
CURRENT_HVAC_FAN = "fan"
|
CURRENT_HVAC_FAN = "fan"
|
||||||
|
|
||||||
|
|
||||||
|
# A list of possible HVAC actions.
|
||||||
|
CURRENT_HVAC_ACTIONS = [
|
||||||
|
CURRENT_HVAC_OFF,
|
||||||
|
CURRENT_HVAC_HEAT,
|
||||||
|
CURRENT_HVAC_COOL,
|
||||||
|
CURRENT_HVAC_DRY,
|
||||||
|
CURRENT_HVAC_IDLE,
|
||||||
|
CURRENT_HVAC_FAN,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
ATTR_AUX_HEAT = "aux_heat"
|
ATTR_AUX_HEAT = "aux_heat"
|
||||||
ATTR_CURRENT_HUMIDITY = "current_humidity"
|
ATTR_CURRENT_HUMIDITY = "current_humidity"
|
||||||
ATTR_CURRENT_TEMPERATURE = "current_temperature"
|
ATTR_CURRENT_TEMPERATURE = "current_temperature"
|
||||||
|
@ -7,7 +7,11 @@ import prometheus_client
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import core as hacore
|
from homeassistant import core as hacore
|
||||||
from homeassistant.components.climate.const import ATTR_CURRENT_TEMPERATURE
|
from homeassistant.components.climate.const import (
|
||||||
|
ATTR_CURRENT_TEMPERATURE,
|
||||||
|
ATTR_HVAC_ACTION,
|
||||||
|
CURRENT_HVAC_ACTIONS,
|
||||||
|
)
|
||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_DEVICE_CLASS,
|
ATTR_DEVICE_CLASS,
|
||||||
@ -166,9 +170,10 @@ class PrometheusMetrics:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _metric(self, metric, factory, documentation, labels=None):
|
def _metric(self, metric, factory, documentation, extra_labels=None):
|
||||||
if labels is None:
|
labels = ["entity", "friendly_name", "domain"]
|
||||||
labels = ["entity", "friendly_name", "domain"]
|
if extra_labels is not None:
|
||||||
|
labels.extend(extra_labels)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return self._metrics[metric]
|
return self._metrics[metric]
|
||||||
@ -303,6 +308,16 @@ class PrometheusMetrics:
|
|||||||
)
|
)
|
||||||
metric.labels(**self._labels(state)).set(current_temp)
|
metric.labels(**self._labels(state)).set(current_temp)
|
||||||
|
|
||||||
|
current_action = state.attributes.get(ATTR_HVAC_ACTION)
|
||||||
|
if current_action:
|
||||||
|
metric = self._metric(
|
||||||
|
"climate_action", self.prometheus_cli.Gauge, "HVAC action", ["action"],
|
||||||
|
)
|
||||||
|
for action in CURRENT_HVAC_ACTIONS:
|
||||||
|
metric.labels(**dict(self._labels(state), action=action)).set(
|
||||||
|
float(action == current_action)
|
||||||
|
)
|
||||||
|
|
||||||
def _handle_sensor(self, state):
|
def _handle_sensor(self, state):
|
||||||
unit = self._unit_string(state.attributes.get(ATTR_UNIT_OF_MEASUREMENT))
|
unit = self._unit_string(state.attributes.get(ATTR_UNIT_OF_MEASUREMENT))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user