Merge pull request #1124 from philipbl/fix_influx

Fix InfluxDB field type conflict
This commit is contained in:
Philip Lundrigan 2016-02-06 20:49:20 -07:00
commit d2e8721918
2 changed files with 9 additions and 12 deletions

View File

@ -70,25 +70,22 @@ def setup(hass, config):
""" Listen for new messages on the bus and sends them to Influx. """ """ Listen for new messages on the bus and sends them to Influx. """
state = event.data.get('new_state') state = event.data.get('new_state')
if state is None or state.state in (STATE_UNKNOWN, ''):
if state is None:
return return
if state.state in (STATE_ON, STATE_LOCKED, STATE_ABOVE_HORIZON): if state.state in (STATE_ON, STATE_LOCKED, STATE_ABOVE_HORIZON):
_state = 1 _state = 1
elif state.state in (STATE_OFF, STATE_UNLOCKED, STATE_UNKNOWN, elif state.state in (STATE_OFF, STATE_UNLOCKED, STATE_BELOW_HORIZON):
STATE_BELOW_HORIZON):
_state = 0 _state = 0
else: else:
_state = state.state
if _state == '':
return
try: try:
_state = float(_state) _state = float(state.state)
except ValueError: 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 = state.entity_id
json_body = [ json_body = [
{ {

View File

@ -7,7 +7,7 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.mqtt/ https://home-assistant.io/components/sensor.mqtt/
""" """
import logging 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.helpers.entity import Entity
from homeassistant.util import template from homeassistant.util import template
import homeassistant.components.mqtt as mqtt import homeassistant.components.mqtt as mqtt
@ -42,7 +42,7 @@ class MqttSensor(Entity):
""" Represents a sensor that can be updated using MQTT. """ """ Represents a sensor that can be updated using MQTT. """
def __init__(self, hass, name, state_topic, qos, unit_of_measurement, def __init__(self, hass, name, state_topic, qos, unit_of_measurement,
value_template): value_template):
self._state = "-" self._state = STATE_UNKNOWN
self._hass = hass self._hass = hass
self._name = name self._name = name
self._state_topic = state_topic self._state_topic = state_topic