mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Decora: Fix set brightness and improve reconnection (#8522)
This commit is contained in:
parent
29266213a0
commit
5e1ff20b09
@ -16,7 +16,7 @@ from homeassistant.components.light import (
|
|||||||
PLATFORM_SCHEMA)
|
PLATFORM_SCHEMA)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['decora==0.6']
|
REQUIREMENTS = ['decora==0.6', 'bluepy==1.1.1']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -39,6 +39,7 @@ def retry(method):
|
|||||||
"""Try send command and retry on error."""
|
"""Try send command and retry on error."""
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
import decora
|
import decora
|
||||||
|
import bluepy
|
||||||
|
|
||||||
initial = time.monotonic()
|
initial = time.monotonic()
|
||||||
while True:
|
while True:
|
||||||
@ -46,7 +47,10 @@ def retry(method):
|
|||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
return method(device, *args, **kwds)
|
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
|
# pylint: disable=protected-access
|
||||||
device._switch.connect()
|
device._switch.connect()
|
||||||
return wrapper_retry
|
return wrapper_retry
|
||||||
@ -119,7 +123,7 @@ class DecoraLight(Light):
|
|||||||
@retry
|
@retry
|
||||||
def set_state(self, brightness):
|
def set_state(self, brightness):
|
||||||
"""Set the state of this lamp to the provided 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
|
self._brightness = brightness
|
||||||
|
|
||||||
@retry
|
@retry
|
||||||
|
@ -106,6 +106,9 @@ blinkstick==1.1.8
|
|||||||
# homeassistant.components.sensor.bitcoin
|
# homeassistant.components.sensor.bitcoin
|
||||||
blockchain==1.3.3
|
blockchain==1.3.3
|
||||||
|
|
||||||
|
# homeassistant.components.light.decora
|
||||||
|
# bluepy==1.1.1
|
||||||
|
|
||||||
# homeassistant.components.notify.aws_lambda
|
# homeassistant.components.notify.aws_lambda
|
||||||
# homeassistant.components.notify.aws_sns
|
# homeassistant.components.notify.aws_sns
|
||||||
# homeassistant.components.notify.aws_sqs
|
# homeassistant.components.notify.aws_sqs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user