Skip to content

Commit

Permalink
LIFX: improve light availability (home-assistant#8451)
Browse files Browse the repository at this point in the history
The default aiolifx timers are tuned for a network with few lost packets.
This means that lights can become "unavailable" from just a two second
dropout. An unavailable light is completely useless for HA until it is
rediscovered so this is an undesirable state to be in.

These tweaks make aiolifx try harder to get its messages through to the
bulbs, at the cost of some latency in detecting lights that actually are
unavailable.
  • Loading branch information
amelchio authored Jul 12, 2017
1 parent b6e0286 commit d10f017
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion homeassistant/components/light/lifx.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@

UDP_BROADCAST_PORT = 56700

DISCOVERY_INTERVAL = 60
MESSAGE_TIMEOUT = 1.0
MESSAGE_RETRIES = 8
UNAVAILABLE_GRACE = 90

CONF_SERVER = 'server'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
Expand Down Expand Up @@ -117,7 +122,10 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
server_addr = config.get(CONF_SERVER)

lifx_manager = LIFXManager(hass, async_add_devices)
lifx_discovery = aiolifx.LifxDiscovery(hass.loop, lifx_manager)
lifx_discovery = aiolifx.LifxDiscovery(
hass.loop,
lifx_manager,
discovery_interval=DISCOVERY_INTERVAL)

coro = hass.loop.create_datagram_endpoint(
lambda: lifx_discovery, local_addr=(server_addr, UDP_BROADCAST_PORT))
Expand Down Expand Up @@ -287,6 +295,9 @@ def register(self, device):
self.hass.async_add_job(entity.async_update_ha_state())
else:
_LOGGER.debug("%s register NEW", device.ip_addr)
device.timeout = MESSAGE_TIMEOUT
device.retry_count = MESSAGE_RETRIES
device.unregister_timeout = UNAVAILABLE_GRACE
device.get_version(self.got_version)

@callback
Expand Down

0 comments on commit d10f017

Please sign in to comment.