Improvements to LIFX reliability (#14848)

* Improve fault tolerance of LIFX initialization

* Update aiolifx to 0.6.3

* Use list comprehension
This commit is contained in:
Anders Melchiorsen 2018-06-07 16:06:29 +02:00 committed by Paulus Schoutsen
parent 83ce9450f7
commit 6b2b92a732
2 changed files with 12 additions and 17 deletions

View file

@ -30,7 +30,7 @@ import homeassistant.util.color as color_util
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['aiolifx==0.6.1', 'aiolifx_effects==0.1.2'] REQUIREMENTS = ['aiolifx==0.6.3', 'aiolifx_effects==0.1.2']
UDP_BROADCAST_PORT = 56700 UDP_BROADCAST_PORT = 56700
@ -201,7 +201,7 @@ def merge_hsbk(base, change):
"""Copy change on top of base, except when None.""" """Copy change on top of base, except when None."""
if change is None: if change is None:
return None return None
return list(map(lambda x, y: y if y is not None else x, base, change)) return [b if c is None else c for b, c in zip(base, change)]
class LIFXManager(object): class LIFXManager(object):
@ -256,7 +256,7 @@ class LIFXManager(object):
async def start_effect(self, entities, service, **kwargs): async def start_effect(self, entities, service, **kwargs):
"""Start a light effect on entities.""" """Start a light effect on entities."""
devices = list(map(lambda l: l.device, entities)) devices = [light.device for light in entities]
if service == SERVICE_EFFECT_PULSE: if service == SERVICE_EFFECT_PULSE:
effect = aiolifx_effects().EffectPulse( effect = aiolifx_effects().EffectPulse(
@ -314,12 +314,13 @@ class LIFXManager(object):
# Read initial state # Read initial state
ack = AwaitAioLIFX().wait ack = AwaitAioLIFX().wait
version_resp = await ack(device.get_version) color_resp = await ack(device.get_color)
if version_resp: if color_resp:
color_resp = await ack(device.get_color) version_resp = await ack(device.get_version)
if version_resp is None or color_resp is None: if color_resp is None or version_resp is None:
_LOGGER.error("Failed to initialize %s", device.ip_addr) _LOGGER.error("Failed to initialize %s", device.ip_addr)
device.registered = False
else: else:
device.timeout = MESSAGE_TIMEOUT device.timeout = MESSAGE_TIMEOUT
device.retry_count = MESSAGE_RETRIES device.retry_count = MESSAGE_RETRIES
@ -440,18 +441,13 @@ class LIFXLight(Light):
@property @property
def brightness(self): def brightness(self):
"""Return the brightness of this light between 0..255.""" """Return the brightness of this light between 0..255."""
brightness = convert_16_to_8(self.device.color[2]) return convert_16_to_8(self.device.color[2])
_LOGGER.debug("brightness: %d", brightness)
return brightness
@property @property
def color_temp(self): def color_temp(self):
"""Return the color temperature.""" """Return the color temperature."""
kelvin = self.device.color[3] kelvin = self.device.color[3]
temperature = color_util.color_temperature_kelvin_to_mired(kelvin) return color_util.color_temperature_kelvin_to_mired(kelvin)
_LOGGER.debug("color_temp: %d", temperature)
return temperature
@property @property
def is_on(self): def is_on(self):
@ -564,7 +560,6 @@ class LIFXLight(Light):
async def async_update(self): async def async_update(self):
"""Update bulb status.""" """Update bulb status."""
_LOGGER.debug("%s async_update", self.who)
if self.available and not self.lock.locked(): if self.available and not self.lock.locked():
await AwaitAioLIFX().wait(self.device.get_color) await AwaitAioLIFX().wait(self.device.get_color)
@ -627,7 +622,7 @@ class LIFXStrip(LIFXColor):
zones = list(range(0, num_zones)) zones = list(range(0, num_zones))
else: else:
zones = list(filter(lambda x: x < num_zones, set(zones))) zones = [x for x in set(zones) if x < num_zones]
# Zone brightness is not reported when powered off # Zone brightness is not reported when powered off
if not self.is_on and hsbk[2] is None: if not self.is_on and hsbk[2] is None:

View file

@ -95,7 +95,7 @@ aiohue==1.5.0
aioimaplib==0.7.13 aioimaplib==0.7.13
# homeassistant.components.light.lifx # homeassistant.components.light.lifx
aiolifx==0.6.1 aiolifx==0.6.3
# homeassistant.components.light.lifx # homeassistant.components.light.lifx
aiolifx_effects==0.1.2 aiolifx_effects==0.1.2