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:
Paul Stenius 2018-07-02 17:03:46 -05:00 committed by Paulus Schoutsen
parent bedd2d7e41
commit 31e23ebae2

View file

@ -10,6 +10,7 @@ import logging
import voluptuous as vol
from aiohttp import web
from homeassistant.components.climate import ATTR_CURRENT_TEMPERATURE
from homeassistant.components.http import HomeAssistantView
from homeassistant.const import (
EVENT_STATE_CHANGED, TEMP_FAHRENHEIT, CONTENT_TYPE_TEXT_PLAIN,
@ -180,6 +181,15 @@ class PrometheusMetrics(object):
'Temperature in degrees Celsius')
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(
'climate_state', self.prometheus_client.Gauge,
'State of the thermostat (0/1)')