From 27530be46fd7550edba2b1725ea6b790b74328cc Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Fri, 6 Dec 2019 13:05:35 +0100 Subject: [PATCH] Move imports to top for influxdb (#29513) --- homeassistant/components/influxdb/__init__.py | 11 +++++------ homeassistant/components/influxdb/sensor.py | 2 +- tests/components/influxdb/test_init.py | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/influxdb/__init__.py b/homeassistant/components/influxdb/__init__.py index 86d489621ea..48852f27910 100644 --- a/homeassistant/components/influxdb/__init__.py +++ b/homeassistant/components/influxdb/__init__.py @@ -1,11 +1,12 @@ """Support for sending data to an Influx database.""" import logging -import re +import math import queue +import re import threading import time -import math +from influxdb import InfluxDBClient, exceptions import requests.exceptions import voluptuous as vol @@ -20,12 +21,12 @@ from homeassistant.const import ( CONF_SSL, CONF_USERNAME, CONF_VERIFY_SSL, - EVENT_STATE_CHANGED, EVENT_HOMEASSISTANT_STOP, + EVENT_STATE_CHANGED, STATE_UNAVAILABLE, STATE_UNKNOWN, ) -from homeassistant.helpers import state as state_helper, event as event_helper +from homeassistant.helpers import event as event_helper, state as state_helper import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_values import EntityValues @@ -118,7 +119,6 @@ RE_DECIMAL = re.compile(r"[^\d.]+") def setup(hass, config): """Set up the InfluxDB component.""" - from influxdb import InfluxDBClient, exceptions conf = config[DOMAIN] @@ -341,7 +341,6 @@ class InfluxThread(threading.Thread): def write_to_influxdb(self, json): """Write preprocessed events to influxdb, with retry.""" - from influxdb import exceptions for retry in range(self.max_tries + 1): try: diff --git a/homeassistant/components/influxdb/sensor.py b/homeassistant/components/influxdb/sensor.py index e94824c9abb..58fbc5605db 100644 --- a/homeassistant/components/influxdb/sensor.py +++ b/homeassistant/components/influxdb/sensor.py @@ -2,6 +2,7 @@ from datetime import timedelta import logging +from influxdb import InfluxDBClient, exceptions import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA @@ -94,7 +95,6 @@ class InfluxSensor(Entity): def __init__(self, hass, influx_conf, query): """Initialize the sensor.""" - from influxdb import InfluxDBClient, exceptions self._name = query.get(CONF_NAME) self._unit_of_measurement = query.get(CONF_UNIT_OF_MEASUREMENT) diff --git a/tests/components/influxdb/test_init.py b/tests/components/influxdb/test_init.py index 26f3c9bcd0b..3e0e1dcf706 100644 --- a/tests/components/influxdb/test_init.py +++ b/tests/components/influxdb/test_init.py @@ -10,7 +10,7 @@ from homeassistant.const import EVENT_STATE_CHANGED, STATE_OFF, STATE_ON, STATE_ from tests.common import get_test_home_assistant -@mock.patch("influxdb.InfluxDBClient") +@mock.patch("homeassistant.components.influxdb.InfluxDBClient") @mock.patch( "homeassistant.components.influxdb.InfluxThread.batch_timeout", mock.Mock(return_value=0),