From fc3741911c636b4fedc9c14f75e2f52298b39eb3 Mon Sep 17 00:00:00 2001 From: Philip Lundrigan Date: Wed, 3 Feb 2016 14:54:41 -0700 Subject: [PATCH 1/3] Fix problem with field type conflict in influxdb --- homeassistant/components/influxdb.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/influxdb.py b/homeassistant/components/influxdb.py index 99b5be37556..ab8a2d76e94 100644 --- a/homeassistant/components/influxdb.py +++ b/homeassistant/components/influxdb.py @@ -70,25 +70,22 @@ def setup(hass, config): """ Listen for new messages on the bus and sends them to Influx. """ state = event.data.get('new_state') - - if state is None: + if state is None or state.state in (STATE_UNKNOWN, ''): return if state.state in (STATE_ON, STATE_LOCKED, STATE_ABOVE_HORIZON): _state = 1 - elif state.state in (STATE_OFF, STATE_UNLOCKED, STATE_UNKNOWN, - STATE_BELOW_HORIZON): + elif state.state in (STATE_OFF, STATE_UNLOCKED, STATE_BELOW_HORIZON): _state = 0 else: - _state = state.state - if _state == '': - return try: - _state = float(_state) + _state = float(state.state) except ValueError: - pass + _state = state.state - measurement = state.attributes.get('unit_of_measurement', state.domain) + measurement = state.attributes.get('unit_of_measurement') + if measurement in (None, ''): + measurement = '{}.{}'.format(state.domain, state.object_id) json_body = [ { From c580953bd87132df09867e169d1662a9d778bf7e Mon Sep 17 00:00:00 2001 From: Philip Lundrigan Date: Wed, 3 Feb 2016 16:54:01 -0700 Subject: [PATCH 2/3] Fix MQTT sensor --- homeassistant/components/sensor/mqtt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/sensor/mqtt.py b/homeassistant/components/sensor/mqtt.py index 8cf2569acd5..032462430e0 100644 --- a/homeassistant/components/sensor/mqtt.py +++ b/homeassistant/components/sensor/mqtt.py @@ -7,7 +7,7 @@ For more details about this platform, please refer to the documentation at https://home-assistant.io/components/sensor.mqtt/ """ import logging -from homeassistant.const import CONF_VALUE_TEMPLATE +from homeassistant.const import CONF_VALUE_TEMPLATE, STATE_UNKNOWN from homeassistant.helpers.entity import Entity from homeassistant.util import template import homeassistant.components.mqtt as mqtt @@ -42,7 +42,7 @@ class MqttSensor(Entity): """ Represents a sensor that can be updated using MQTT. """ def __init__(self, hass, name, state_topic, qos, unit_of_measurement, value_template): - self._state = "-" + self._state = STATE_UNKNOWN self._hass = hass self._name = name self._state_topic = state_topic From bbdc1961271acf0dd0ad8818d41b84eea4a5aec4 Mon Sep 17 00:00:00 2001 From: Philip Lundrigan Date: Sat, 6 Feb 2016 20:33:43 -0700 Subject: [PATCH 3/3] Use entity_id attribute --- homeassistant/components/influxdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/influxdb.py b/homeassistant/components/influxdb.py index ab8a2d76e94..123cf5bc0e3 100644 --- a/homeassistant/components/influxdb.py +++ b/homeassistant/components/influxdb.py @@ -85,7 +85,7 @@ def setup(hass, config): measurement = state.attributes.get('unit_of_measurement') if measurement in (None, ''): - measurement = '{}.{}'.format(state.domain, state.object_id) + measurement = state.entity_id json_body = [ {