From e8c6d6436c994b9968ea6ac4f04fbe053fb0ba81 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Sun, 25 Feb 2018 21:45:06 +0100 Subject: [PATCH 1/3] Remove deprecated CONF_RETRY_QUEUE --- homeassistant/components/influxdb.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/homeassistant/components/influxdb.py b/homeassistant/components/influxdb.py index 08c94d54361eb3..3827131920c3ad 100644 --- a/homeassistant/components/influxdb.py +++ b/homeassistant/components/influxdb.py @@ -35,7 +35,6 @@ CONF_COMPONENT_CONFIG_GLOB = 'component_config_glob' CONF_COMPONENT_CONFIG_DOMAIN = 'component_config_domain' CONF_RETRY_COUNT = 'max_retries' -CONF_RETRY_QUEUE = 'retry_queue_limit' DEFAULT_DATABASE = 'home_assistant' DEFAULT_VERIFY_SSL = True @@ -53,7 +52,7 @@ }) CONFIG_SCHEMA = vol.Schema({ - DOMAIN: vol.All(cv.deprecated(CONF_RETRY_QUEUE), vol.Schema({ + DOMAIN: vol.All(vol.Schema({ vol.Optional(CONF_HOST): cv.string, vol.Inclusive(CONF_USERNAME, 'authentication'): cv.string, vol.Inclusive(CONF_PASSWORD, 'authentication'): cv.string, @@ -71,7 +70,6 @@ vol.Optional(CONF_PORT): cv.port, vol.Optional(CONF_SSL): cv.boolean, vol.Optional(CONF_RETRY_COUNT, default=0): cv.positive_int, - vol.Optional(CONF_RETRY_QUEUE, default=20): cv.positive_int, vol.Optional(CONF_DEFAULT_MEASUREMENT): cv.string, vol.Optional(CONF_OVERRIDE_MEASUREMENT): cv.string, vol.Optional(CONF_TAGS, default={}): From f2cb2e2fcc5746870cc78abe4a97739bf2095501 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Sun, 25 Feb 2018 19:24:36 +0100 Subject: [PATCH 2/3] Close influxdb on shutdown --- homeassistant/components/influxdb.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/influxdb.py b/homeassistant/components/influxdb.py index 3827131920c3ad..4c4df656705ee3 100644 --- a/homeassistant/components/influxdb.py +++ b/homeassistant/components/influxdb.py @@ -232,6 +232,7 @@ def shutdown(event): """Shut down the thread.""" instance.queue.put(None) instance.join() + influx.close() hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, shutdown) From acb984f1d45ba2d61c4b954adfc8260675d936b7 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Sun, 25 Feb 2018 21:16:38 +0100 Subject: [PATCH 3/3] Ignore inf as an influxdb value --- homeassistant/components/influxdb.py | 4 ++++ tests/components/test_influxdb.py | 31 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/homeassistant/components/influxdb.py b/homeassistant/components/influxdb.py index 4c4df656705ee3..1f7f9f6262f8ed 100644 --- a/homeassistant/components/influxdb.py +++ b/homeassistant/components/influxdb.py @@ -220,6 +220,10 @@ def event_to_json(event): json['fields'][key] = float( RE_DECIMAL.sub('', new_value)) + # Infinity is not a valid float in InfluxDB + if (key, float("inf")) in json['fields'].items(): + del json['fields'][key] + json['tags'].update(tags) return json diff --git a/tests/components/test_influxdb.py b/tests/components/test_influxdb.py index feaa0f35622332..c909a8488be43e 100644 --- a/tests/components/test_influxdb.py +++ b/tests/components/test_influxdb.py @@ -213,6 +213,37 @@ def test_event_listener_no_units(self, mock_client): ) mock_client.return_value.write_points.reset_mock() + def test_event_listener_inf(self, mock_client): + """Test the event listener for missing units.""" + self._setup() + + attrs = {'bignumstring': "9" * 999} + state = mock.MagicMock( + state=8, domain='fake', entity_id='fake.entity-id', + object_id='entity', attributes=attrs) + event = mock.MagicMock(data={'new_state': state}, time_fired=12345) + body = [{ + 'measurement': 'fake.entity-id', + 'tags': { + 'domain': 'fake', + 'entity_id': 'entity', + }, + 'time': 12345, + 'fields': { + 'value': 8, + }, + }] + self.handler_method(event) + self.hass.data[influxdb.DOMAIN].block_till_done() + self.assertEqual( + mock_client.return_value.write_points.call_count, 1 + ) + self.assertEqual( + mock_client.return_value.write_points.call_args, + mock.call(body) + ) + mock_client.return_value.write_points.reset_mock() + def test_event_listener_states(self, mock_client): """Test the event listener against ignored states.""" self._setup()