8000 Export climate status and target temperature to Prometheus by hudashot · Pull Request #10919 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Export climate status and target temperature to Prometheus #10919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions homeassistant/components/prometheus.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from homeassistant.components import recorder
from homeassistant.const import (
CONF_DOMAINS, CONF_ENTITIES, CONF_EXCLUDE, CONF_INCLUDE, TEMP_CELSIUS,
EVENT_STATE_CHANGED, TEMP_FAHRENHEIT, CONTENT_TYPE_TEXT_PLAIN)
EVENT_STATE_CHANGED, TEMP_FAHRENHEIT, CONTENT_TYPE_TEXT_PLAIN,
ATTR_TEMPERATURE, ATTR_UNIT_OF_MEASUREMENT)
from homeassistant import core as hacore
from homeassistant.helpers import state as state_helper
from homeassistant.util.temperature import fahrenheit_to_celsius
Expand Down Expand Up @@ -159,6 +160,26 @@ def _handle_lock(self, state):
value = state_helper.state_as_number(state)
metric.labels(**self._labels(state)).set(value)

def _handle_climate(self, state):
temp = state.attributes.get(ATTR_TEMPERATURE)
if temp:
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
if unit == TEMP_FAHRENHEIT:
temp = fahrenheit_to_celsius(temp)
metric = self._metric(
'temperature_c', self.prometheus_client.Gauge,
'Temperature in degrees Celsius')
metric.labels(**self._labels(state)).set(temp)

metric = self._metric(
'climate_state', self.prometheus_client.Gauge,
'State of the thermostat (0/1)')
try:
value = state_helper.state_as_number(state)
metric.labels(**self._labels(state)).set(value)
except ValueError:
pass

def _handle_sensor(self, state):
_sensor_types = {
TEMP_CELSIUS: (
Expand Down Expand Up @@ -191,7 +212,7 @@ def _handle_sensor(self, state):
),
}

unit = state.attributes.get('unit_of_measurement')
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
metric = _sensor_types.get(unit)

if metric is not None:
Expand Down
8 changes: 5 additions & 3 deletions homeassistant/helpers/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
ATTR_HUMIDITY, ATTR_OPERATION_MODE, ATTR_SWING_MODE,
SERVICE_SET_AUX_HEAT, SERVICE_SET_AWAY_MODE, SERVICE_SET_HOLD_MODE,
SERVICE_SET_FAN_MODE, SERVICE_SET_HUMIDITY, SERVICE_SET_OPERATION_MODE,
SERVICE_SET_SWING_MODE, SERVICE_SET_TEMPERATURE)
SERVICE_SET_SWING_MODE, SERVICE_SET_TEMPERATURE, STATE_HEAT, STATE_COOL,
STATE_IDLE)
from homeassistant.components.climate.ecobee import (
ATTR_FAN_MIN_ON_TIME, SERVICE_SET_FAN_MIN_ON_TIME,
ATTR_RESUME_ALL, SERVICE_RESUME_PROGRAM)
Expand Down Expand Up @@ -210,10 +211,11 @@ def state_as_number(state):
Raises ValueError if this is not possible.
"""
if state.state in (STATE_ON, STATE_LOCKED, STATE_ABOVE_HORIZON,
STATE_OPEN, STATE_HOME):
STATE_OPEN, STATE_HOME, STATE_HEAT, STATE_COOL):
return 1
elif state.state in (STATE_OFF, STATE_UNLOCKED, STATE_UNKNOWN,
STATE_BELOW_HORIZON, STATE_CLOSED, STATE_NOT_HOME):
STATE_BELOW_HORIZON, STATE_CLOSED, STATE_NOT_HOME,
STATE_IDLE):
return 0

return float(state.state)
0