Move imports to top for influxdb (#29513)

This commit is contained in:
springstan 2019-12-06 13:05:35 +01:00 committed by Fabian Affolter
parent ec3ffe309a
commit 27530be46f
3 changed files with 7 additions and 8 deletions

View file

@ -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:

View file

@ -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)

View file

@ -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),