From 31e23ebae2f227968b9d184e6bb7f5ba9797dd88 Mon Sep 17 00:00:00 2001 From: Paul Stenius Date: Mon, 2 Jul 2018 17:03:46 -0500 Subject: [PATCH] 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 --- homeassistant/components/prometheus.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/homeassistant/components/prometheus.py b/homeassistant/components/prometheus.py index 6f233dafe08..0a6c959f243 100644 --- a/homeassistant/components/prometheus.py +++ b/homeassistant/components/prometheus.py @@ -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)')