Move imports in decora component (#27645)

* moved imports to top level

* replaced importlib with standard import

* fix for Unable to import 'decora' error
This commit is contained in:
bouni 2019-10-15 12:26:50 +02:00 committed by Pascal Vizeli
parent 3d7860391a
commit b4a73fa87e

View file

@ -1,18 +1,19 @@
"""Support for Decora dimmers."""
import importlib
import logging
from functools import wraps
import logging
import time
from bluepy.btle import BTLEException # pylint: disable=import-error, no-member
import decora # pylint: disable=import-error, no-member
import voluptuous as vol
from homeassistant.const import CONF_API_KEY, CONF_DEVICES, CONF_NAME
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
PLATFORM_SCHEMA,
SUPPORT_BRIGHTNESS,
Light,
PLATFORM_SCHEMA,
)
from homeassistant.const import CONF_API_KEY, CONF_DEVICES, CONF_NAME
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
@ -34,9 +35,6 @@ def retry(method):
@wraps(method)
def wrapper_retry(device, *args, **kwargs):
"""Try send command and retry on error."""
# pylint: disable=import-error, no-member
import decora
import bluepy
initial = time.monotonic()
while True:
@ -44,7 +42,7 @@ def retry(method):
return None
try:
return method(device, *args, **kwargs)
except (decora.decoraException, AttributeError, bluepy.btle.BTLEException):
except (decora.decoraException, AttributeError, BTLEException):
_LOGGER.warning(
"Decora connect error for device %s. " "Reconnecting...",
device.name,
@ -74,8 +72,6 @@ class DecoraLight(Light):
def __init__(self, device):
"""Initialize the light."""
# pylint: disable=no-member
decora = importlib.import_module("decora")
self._name = device["name"]
self._address = device["address"]