use labels

This commit is contained in:
Matt Zimmerman
2021-07-31 12:46:46 -07:00
parent dcec106b55
commit 09c56d6359

View File

@@ -317,7 +317,12 @@ class PrometheusMetrics:
value = self.state_as_number(state) value = self.state_as_number(state)
metric.labels(**self._labels(state)).set(value) metric.labels(**self._labels(state)).set(value)
def _handle_climate_temp(self, state, attr, metric_name, metric_description): def _handle_climate_temp(
self, state, attr, metric_name, metric_description, metric_labels=None
):
if metric_labels is None:
metric_labels = {}
temp = state.attributes.get(attr) temp = state.attributes.get(attr)
if temp: if temp:
if self._climate_units == TEMP_FAHRENHEIT: if self._climate_units == TEMP_FAHRENHEIT:
@@ -327,7 +332,7 @@ class PrometheusMetrics:
self.prometheus_cli.Gauge, self.prometheus_cli.Gauge,
metric_description, metric_description,
) )
metric.labels(**self._labels(state)).set(temp) metric.labels({**metric_labels, **self._labels(state)}).set(temp)
def _handle_climate(self, state): def _handle_climate(self, state):
self._handle_climate_temp( self._handle_climate_temp(
@@ -336,23 +341,25 @@ class PrometheusMetrics:
"climate_target_temperature_celsius", "climate_target_temperature_celsius",
"Target temperature in degrees Celsius", "Target temperature in degrees Celsius",
) )
self._handle_climate_temp(
state,
ATTR_CURRENT_TEMPERATURE,
"climate_current_temperature_celsius",
"Current temperature in degrees Celsius",
)
self._handle_climate_temp( self._handle_climate_temp(
state, state,
ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_HIGH,
"climate_target_temperature_high_c", "climate_target_temperature_celsius",
"Target high temperature in degrees Celsius", "Target temperature in degrees Celsius",
{"point": "high"},
) )
self._handle_climate_temp( self._handle_climate_temp(
state, state,
ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_LOW,
"climate_target_temperature_low_c", "climate_target_temperature_celsius",
"Target low temperature in degrees Celsius", "Target temperature in degrees Celsius",
{"point": "low"},
)
self._handle_climate_temp(
state,
ATTR_CURRENT_TEMPERATURE,
"climate_current_temperature_celsius",
"Current temperature in degrees Celsius",
) )
current_action = state.attributes.get(ATTR_HVAC_ACTION) current_action = state.attributes.get(ATTR_HVAC_ACTION)