From b4a73fa87e97be9d5b562554ea42c88b7c150644 Mon Sep 17 00:00:00 2001 From: bouni Date: Tue, 15 Oct 2019 12:26:50 +0200 Subject: [PATCH] Move imports in decora component (#27645) * moved imports to top level * replaced importlib with standard import * fix for Unable to import 'decora' error --- homeassistant/components/decora/light.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/decora/light.py b/homeassistant/components/decora/light.py index cad98f9d8a4..4d2d10ccbd5 100644 --- a/homeassistant/components/decora/light.py +++ b/homeassistant/components/decora/light.py @@ -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"]