Decora: Fix set brightness and improve reconnection (#8522)

This commit is contained in:
Thibault Cohen
2017-07-18 18:02:42 -04:00
committed by Pascal Vizeli
parent 29266213a0
commit 5e1ff20b09
2 changed files with 10 additions and 3 deletions

View File

@ -16,7 +16,7 @@ from homeassistant.components.light import (
PLATFORM_SCHEMA)
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['decora==0.6']
REQUIREMENTS = ['decora==0.6', 'bluepy==1.1.1']
_LOGGER = logging.getLogger(__name__)
@ -39,6 +39,7 @@ def retry(method):
"""Try send command and retry on error."""
# pylint: disable=import-error
import decora
import bluepy
initial = time.monotonic()
while True:
@ -46,7 +47,10 @@ def retry(method):
return None
try:
return method(device, *args, **kwds)
except (decora.decoraException, AttributeError):
except (decora.decoraException, AttributeError,
bluepy.btle.BTLEException):
_LOGGER.warning("Decora connect error for device %s. "
"Reconnecting...", device.name)
# pylint: disable=protected-access
device._switch.connect()
return wrapper_retry
@ -119,7 +123,7 @@ class DecoraLight(Light):
@retry
def set_state(self, brightness):
"""Set the state of this lamp to the provided brightness."""
self._switch.set_brightness(brightness / 2.55)
self._switch.set_brightness(int(brightness / 2.55))
self._brightness = brightness
@retry

View File

@ -106,6 +106,9 @@ blinkstick==1.1.8
# homeassistant.components.sensor.bitcoin
blockchain==1.3.3
# homeassistant.components.light.decora
# bluepy==1.1.1
# homeassistant.components.notify.aws_lambda
# homeassistant.components.notify.aws_sns
# homeassistant.components.notify.aws_sqs