expose climate current temperature in prometeus metrics (#15232)
* expose climate current temperature in prometeus metrics * import ATTR_CURRENT_TEMPERATURE from climate instead of const * remove duplicated ATTR_CURRENT_TEMPERATURE from const * fix ATTR_CURRENT_TEMPERATURE import
This commit is contained in:
parent
bedd2d7e41
commit
31e23ebae2
1 changed files with 10 additions and 0 deletions
|
@ -10,6 +10,7 @@ import logging
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
|
||||||
|
from homeassistant.components.climate import ATTR_CURRENT_TEMPERATURE
|
||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
EVENT_STATE_CHANGED, TEMP_FAHRENHEIT, CONTENT_TYPE_TEXT_PLAIN,
|
EVENT_STATE_CHANGED, TEMP_FAHRENHEIT, CONTENT_TYPE_TEXT_PLAIN,
|
||||||
|
@ -180,6 +181,15 @@ class PrometheusMetrics(object):
|
||||||
'Temperature in degrees Celsius')
|
'Temperature in degrees Celsius')
|
||||||
metric.labels(**self._labels(state)).set(temp)
|
metric.labels(**self._labels(state)).set(temp)
|
||||||
|
|
||||||
|
current_temp = state.attributes.get(ATTR_CURRENT_TEMPERATURE)
|
||||||
|
if current_temp:
|
||||||
|
if unit == TEMP_FAHRENHEIT:
|
||||||
|
current_temp = fahrenheit_to_celsius(current_temp)
|
||||||
|
metric = self._metric(
|
||||||
|
'current_temperature_c', self.prometheus_client.Gauge,
|
||||||
|
'Current Temperature in degrees Celsius')
|
||||||
|
metric.labels(**self._labels(state)).set(current_temp)
|
||||||
|
|
||||||
metric = self._metric(
|
metric = self._metric(
|
||||||
'climate_state', self.prometheus_client.Gauge,
|
'climate_state', self.prometheus_client.Gauge,
|
||||||
'State of the thermostat (0/1)')
|
'State of the thermostat (0/1)')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue