Skip to content
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

InfluxDB cleanups #12903

Merged
merged 3 commits into from Mar 4, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions homeassistant/components/influxdb.py
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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={}):
Expand Down Expand Up @@ -222,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
Expand All @@ -234,6 +236,7 @@ def shutdown(event):
"""Shut down the thread."""
instance.queue.put(None)
instance.join()
influx.close()

hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, shutdown)

Expand Down
31 changes: 31 additions & 0 deletions tests/components/test_influxdb.py
Expand Up @@ -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()
Expand Down