mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Add HVAC modes of climate entities to Prometheus exporter (#62144)
This commit is contained in:
parent
8e835df8d4
commit
d11f2b5151
@ -11,6 +11,7 @@ from homeassistant import core as hacore
|
||||
from homeassistant.components.climate.const import (
|
||||
ATTR_CURRENT_TEMPERATURE,
|
||||
ATTR_HVAC_ACTION,
|
||||
ATTR_HVAC_MODES,
|
||||
ATTR_TARGET_TEMP_HIGH,
|
||||
ATTR_TARGET_TEMP_LOW,
|
||||
CURRENT_HVAC_ACTIONS,
|
||||
@ -393,6 +394,20 @@ class PrometheusMetrics:
|
||||
float(action == current_action)
|
||||
)
|
||||
|
||||
current_mode = state.state
|
||||
available_modes = state.attributes.get(ATTR_HVAC_MODES)
|
||||
if current_mode and available_modes:
|
||||
metric = self._metric(
|
||||
"climate_mode",
|
||||
self.prometheus_cli.Gauge,
|
||||
"HVAC mode",
|
||||
["mode"],
|
||||
)
|
||||
for mode in available_modes:
|
||||
metric.labels(**dict(self._labels(state), mode=mode)).set(
|
||||
float(mode == current_mode)
|
||||
)
|
||||
|
||||
def _handle_humidifier(self, state):
|
||||
humidifier_target_humidity_percent = state.attributes.get(ATTR_HUMIDITY)
|
||||
if humidifier_target_humidity_percent:
|
||||
|
@ -419,7 +419,7 @@ async def test_battery(hass, hass_client):
|
||||
|
||||
|
||||
async def test_climate(hass, hass_client):
|
||||
"""Test prometheus metrics for battery."""
|
||||
"""Test prometheus metrics for climate."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"conversation",
|
||||
@ -459,6 +459,20 @@ async def test_climate(hass, hass_client):
|
||||
'friendly_name="Ecobee"} 24.0' in body
|
||||
)
|
||||
|
||||
assert (
|
||||
'climate_mode{domain="climate",'
|
||||
'entity="climate.heatpump",'
|
||||
'friendly_name="HeatPump",'
|
||||
'mode="heat"} 1.0' in body
|
||||
)
|
||||
|
||||
assert (
|
||||
'climate_mode{domain="climate",'
|
||||
'entity="climate.heatpump",'
|
||||
'friendly_name="HeatPump",'
|
||||
'mode="off"} 0.0' in body
|
||||
)
|
||||
|
||||
|
||||
async def test_humidifier(hass, hass_client):
|
||||
"""Test prometheus metrics for battery."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user