mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Merge pull request #943 from trollkarlen/influxdb-fix
influxdb: fix the need of admin to run
This commit is contained in:
commit
ec2d9af8dc
@ -51,14 +51,11 @@ def setup(hass, config):
|
|||||||
try:
|
try:
|
||||||
influx = InfluxDBClient(host=host, port=port, username=username,
|
influx = InfluxDBClient(host=host, port=port, username=username,
|
||||||
password=password, database=database)
|
password=password, database=database)
|
||||||
databases = [i['name'] for i in influx.get_list_database()]
|
influx.query("select * from /.*/ LIMIT 1;")
|
||||||
except exceptions.InfluxDBClientError:
|
except exceptions.InfluxDBClientError as exc:
|
||||||
_LOGGER.error("Database host is not accessible. "
|
_LOGGER.error("Database host is not accessible due to '%s', please "
|
||||||
"Please check your entries in the configuration file.")
|
"check your entries in the configuration file and that"
|
||||||
return False
|
" the database exists and is READ/WRITE.", exc)
|
||||||
|
|
||||||
if database not in databases:
|
|
||||||
_LOGGER.error("Database %s doesn't exist", database)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def influx_event_listener(event):
|
def influx_event_listener(event):
|
||||||
@ -76,6 +73,8 @@ def setup(hass, config):
|
|||||||
_state = 0
|
_state = 0
|
||||||
else:
|
else:
|
||||||
_state = state.state
|
_state = state.state
|
||||||
|
if _state == '':
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
_state = float(_state)
|
_state = float(_state)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -100,7 +99,7 @@ def setup(hass, config):
|
|||||||
try:
|
try:
|
||||||
influx.write_points(json_body)
|
influx.write_points(json_body)
|
||||||
except exceptions.InfluxDBClientError:
|
except exceptions.InfluxDBClientError:
|
||||||
_LOGGER.exception('Error saving event to InfluxDB')
|
_LOGGER.exception('Error saving event "%s" to InfluxDB', json_body)
|
||||||
|
|
||||||
hass.bus.listen(EVENT_STATE_CHANGED, influx_event_listener)
|
hass.bus.listen(EVENT_STATE_CHANGED, influx_event_listener)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user