mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
influxdb: fix the need of admin to run
Use select statment to show if db exits instead of 'SHOW DATABASES' which cant be run by a non admin user. See https://github.com/influxdata/influxdb/issues/4785 for more info. Also influxdb dont like empty writes('') so ignore state changes of that kind, this happens on startup of home assistant. Signed-off-by: Robert Marklund <robbelibobban@gmail.com>
This commit is contained in:
parent
85df9e98bd
commit
89aa3cbc62
@ -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