mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Add Prometheus fan_mode and climate_mode metrics (#120267)
Co-authored-by: Anton Tolchanov <1687799+knyar@users.noreply.github.com>
This commit is contained in:
parent
26bc37195e
commit
cd72bdd851
@ -16,6 +16,8 @@ import voluptuous as vol
|
|||||||
from homeassistant import core as hacore
|
from homeassistant import core as hacore
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
ATTR_CURRENT_TEMPERATURE,
|
ATTR_CURRENT_TEMPERATURE,
|
||||||
|
ATTR_FAN_MODE,
|
||||||
|
ATTR_FAN_MODES,
|
||||||
ATTR_HVAC_ACTION,
|
ATTR_HVAC_ACTION,
|
||||||
ATTR_HVAC_MODES,
|
ATTR_HVAC_MODES,
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
@ -556,6 +558,34 @@ class PrometheusMetrics:
|
|||||||
float(mode == current_mode)
|
float(mode == current_mode)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
preset_mode = state.attributes.get(ATTR_PRESET_MODE)
|
||||||
|
available_preset_modes = state.attributes.get(ATTR_PRESET_MODES)
|
||||||
|
if preset_mode and available_preset_modes:
|
||||||
|
preset_metric = self._metric(
|
||||||
|
"climate_preset_mode",
|
||||||
|
prometheus_client.Gauge,
|
||||||
|
"Preset mode enum",
|
||||||
|
["mode"],
|
||||||
|
)
|
||||||
|
for mode in available_preset_modes:
|
||||||
|
preset_metric.labels(**dict(self._labels(state), mode=mode)).set(
|
||||||
|
float(mode == preset_mode)
|
||||||
|
)
|
||||||
|
|
||||||
|
fan_mode = state.attributes.get(ATTR_FAN_MODE)
|
||||||
|
available_fan_modes = state.attributes.get(ATTR_FAN_MODES)
|
||||||
|
if fan_mode and available_fan_modes:
|
||||||
|
fan_mode_metric = self._metric(
|
||||||
|
"climate_fan_mode",
|
||||||
|
prometheus_client.Gauge,
|
||||||
|
"Fan mode enum",
|
||||||
|
["mode"],
|
||||||
|
)
|
||||||
|
for mode in available_fan_modes:
|
||||||
|
fan_mode_metric.labels(**dict(self._labels(state), mode=mode)).set(
|
||||||
|
float(mode == fan_mode)
|
||||||
|
)
|
||||||
|
|
||||||
def _handle_humidifier(self, state: State) -> None:
|
def _handle_humidifier(self, state: State) -> None:
|
||||||
humidifier_target_humidity_percent = state.attributes.get(ATTR_HUMIDITY)
|
humidifier_target_humidity_percent = state.attributes.get(ATTR_HUMIDITY)
|
||||||
if humidifier_target_humidity_percent:
|
if humidifier_target_humidity_percent:
|
||||||
|
@ -31,8 +31,11 @@ from homeassistant.components import (
|
|||||||
)
|
)
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
ATTR_CURRENT_TEMPERATURE,
|
ATTR_CURRENT_TEMPERATURE,
|
||||||
|
ATTR_FAN_MODE,
|
||||||
|
ATTR_FAN_MODES,
|
||||||
ATTR_HUMIDITY,
|
ATTR_HUMIDITY,
|
||||||
ATTR_HVAC_ACTION,
|
ATTR_HVAC_ACTION,
|
||||||
|
ATTR_HVAC_MODES,
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
)
|
)
|
||||||
@ -405,6 +408,18 @@ async def test_climate(
|
|||||||
'entity="climate.fritzdect",'
|
'entity="climate.fritzdect",'
|
||||||
'friendly_name="Fritz!DECT"} 0.0' in body
|
'friendly_name="Fritz!DECT"} 0.0' in body
|
||||||
)
|
)
|
||||||
|
assert (
|
||||||
|
'climate_preset_mode{domain="climate",'
|
||||||
|
'entity="climate.ecobee",'
|
||||||
|
'friendly_name="Ecobee",'
|
||||||
|
'mode="away"} 1.0' in body
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
'climate_fan_mode{domain="climate",'
|
||||||
|
'entity="climate.ecobee",'
|
||||||
|
'friendly_name="Ecobee",'
|
||||||
|
'mode="auto"} 1.0' in body
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("namespace", [""])
|
@pytest.mark.parametrize("namespace", [""])
|
||||||
@ -1414,6 +1429,11 @@ async def climate_fixture(
|
|||||||
ATTR_TARGET_TEMP_LOW: 21,
|
ATTR_TARGET_TEMP_LOW: 21,
|
||||||
ATTR_TARGET_TEMP_HIGH: 24,
|
ATTR_TARGET_TEMP_HIGH: 24,
|
||||||
ATTR_HVAC_ACTION: climate.HVACAction.COOLING,
|
ATTR_HVAC_ACTION: climate.HVACAction.COOLING,
|
||||||
|
ATTR_HVAC_MODES: ["off", "heat", "cool", "heat_cool"],
|
||||||
|
ATTR_PRESET_MODE: "away",
|
||||||
|
ATTR_PRESET_MODES: ["away", "home", "sleep"],
|
||||||
|
ATTR_FAN_MODE: "auto",
|
||||||
|
ATTR_FAN_MODES: ["auto", "on"],
|
||||||
}
|
}
|
||||||
set_state_with_entry(
|
set_state_with_entry(
|
||||||
hass, climate_2, climate.HVACAction.HEATING, climate_2_attributes
|
hass, climate_2, climate.HVACAction.HEATING, climate_2_attributes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user