Fixes: flake8, missing import of exception and better handling of ble problems

This commit is contained in:
Sören Müller
2019-06-05 02:01:47 +02:00
parent 89b69cc6a1
commit bfa7e7d453

View File

@@ -4,6 +4,7 @@ import logging
from homeassistant.components.light import ( from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_HS_COLOR, SUPPORT_BRIGHTNESS, ATTR_BRIGHTNESS, ATTR_HS_COLOR, SUPPORT_BRIGHTNESS,
SUPPORT_COLOR, Light) SUPPORT_COLOR, Light)
from homeassistant.exceptions import PlatformNotReady
import homeassistant.util.color as color_util import homeassistant.util.color as color_util
@@ -20,7 +21,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
try: try:
for bulb in nearbyBulbs: for bulb in nearbyBulbs:
bulb.get_name() bulb.get_name()
except: bulb.get_brightness()
except Exception:
raise PlatformNotReady raise PlatformNotReady
add_devices(AveaLight(bulb) for bulb in nearbyBulbs) add_devices(AveaLight(bulb) for bulb in nearbyBulbs)
@@ -34,7 +36,7 @@ class AveaLight(Light):
self._light = light self._light = light
self._name = light.name self._name = light.name
self._state = None self._state = None
self._brightness = None self._brightness = light.brightness
@property @property
def supported_features(self): def supported_features(self):
@@ -86,6 +88,7 @@ class AveaLight(Light):
This is the only method that should fetch new data for Home Assistant. This is the only method that should fetch new data for Home Assistant.
""" """
brightness = self._light.get_brightness() brightness = self._light.get_brightness()
if brightness is not None:
if brightness == 0: if brightness == 0:
self._state = False self._state = False
else: else: