diff --git a/homeassistant/components/light/limitlessled.py b/homeassistant/components/light/limitlessled.py index 9096bb32a10..ba8b8235260 100644 --- a/homeassistant/components/light/limitlessled.py +++ b/homeassistant/components/light/limitlessled.py @@ -19,11 +19,15 @@ configuration.yaml file. light: platform: limitlessled - host: 192.168.1.10 - group_1_name: Living Room - group_2_name: Bedroom - group_3_name: Office - group_4_name: Kitchen + bridges: + - host: 192.168.1.10 + group_1_name: Living Room + group_2_name: Bedroom + group_3_name: Office + group_3_type: white + group_4_name: Kitchen + - host: 192.168.1.11 + group_2_name: Basement """ import logging @@ -33,19 +37,30 @@ from homeassistant.components.light import (Light, ATTR_BRIGHTNESS, from homeassistant.util.color import color_RGB_to_xy _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['ledcontroller==1.0.7'] +REQUIREMENTS = ['ledcontroller==1.1.0'] def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Gets the LimitlessLED lights. """ import ledcontroller - led = ledcontroller.LedController(config['host']) + # Handle old configuration format: + bridges = config.get('bridges', [config]) + + for bridge_id, bridge in enumerate(bridges): + bridge['id'] = bridge_id + + pool = ledcontroller.LedControllerPool([x['host'] for x in bridges]) lights = [] - for i in range(1, 5): - if 'group_%d_name' % (i) in config: - lights.append(LimitlessLED(led, i, config['group_%d_name' % (i)])) + for bridge in bridges: + for i in range(1, 5): + name_key = 'group_%d_name' % i + if name_key in bridge: + group_type = bridge.get('group_%d_type' % i, 'rgbw') + lights.append(LimitlessLED.factory(pool, bridge['id'], i, + bridge[name_key], + group_type)) add_devices_callback(lights) @@ -53,15 +68,57 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): class LimitlessLED(Light): """ Represents a LimitlessLED light """ - def __init__(self, led, group, name): - self.led = led + @staticmethod + def factory(pool, controller_id, group, name, group_type): + ''' Construct a Limitless LED of the appropriate type ''' + if group_type == 'white': + return WhiteLimitlessLED(pool, controller_id, group, name) + elif group_type == 'rgbw': + return RGBWLimitlessLED(pool, controller_id, group, name) + + # pylint: disable=too-many-arguments + def __init__(self, pool, controller_id, group, name, group_type): + self.pool = pool + self.controller_id = controller_id self.group = group + self.pool.execute(self.controller_id, "set_group_type", self.group, + group_type) + # LimitlessLEDs don't report state, we have track it ourselves. - self.led.off(self.group) + self.pool.execute(self.controller_id, "off", self.group) self._name = name or DEVICE_DEFAULT_NAME self._state = False + + @property + def should_poll(self): + """ No polling needed. """ + return False + + @property + def name(self): + """ Returns the name of the device if any. """ + return self._name + + @property + def is_on(self): + """ True if device is on. """ + return self._state + + def turn_off(self, **kwargs): + """ Turn the device off. """ + self._state = False + self.pool.execute(self.controller_id, "off", self.group) + self.update_ha_state() + + +class RGBWLimitlessLED(LimitlessLED): + """ Represents a RGBW LimitlessLED light """ + + def __init__(self, pool, controller_id, group, name): + super().__init__(pool, controller_id, group, name, 'rgbw') + self._brightness = 100 self._xy_color = color_RGB_to_xy(255, 255, 255) @@ -87,16 +144,6 @@ class LimitlessLED(Light): ((0xE6, 0xE6, 0xFA), 'lavendar'), ]] - @property - def should_poll(self): - """ No polling needed for a demo light. """ - return False - - @property - def name(self): - """ Returns the name of the device if any. """ - return self._name - @property def brightness(self): return self._brightness @@ -117,11 +164,6 @@ class LimitlessLED(Light): # First candidate in the sorted list is closest to desired color: return sorted(candidates)[0][1] - @property - def is_on(self): - """ True if device is on. """ - return self._state - def turn_on(self, **kwargs): """ Turn the device on. """ self._state = True @@ -132,12 +174,21 @@ class LimitlessLED(Light): if ATTR_XY_COLOR in kwargs: self._xy_color = kwargs[ATTR_XY_COLOR] - self.led.set_color(self._xy_to_led_color(self._xy_color), self.group) - self.led.set_brightness(self._brightness / 255.0, self.group) + self.pool.execute(self.controller_id, "set_color", + self._xy_to_led_color(self._xy_color), self.group) + self.pool.execute(self.controller_id, "set_brightness", + self._brightness / 255.0, self.group) self.update_ha_state() - def turn_off(self, **kwargs): - """ Turn the device off. """ - self._state = False - self.led.off(self.group) + +class WhiteLimitlessLED(LimitlessLED): + """ Represents a White LimitlessLED light """ + + def __init__(self, pool, controller_id, group, name): + super().__init__(pool, controller_id, group, name, 'white') + + def turn_on(self, **kwargs): + """ Turn the device on. """ + self._state = True + self.pool.execute(self.controller_id, "on", self.group) self.update_ha_state() diff --git a/requirements_all.txt b/requirements_all.txt index d65516a7dd6..2b7074d91cd 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -14,7 +14,7 @@ astral==0.8.1 phue==0.8 # Limitlessled/Easybulb/Milight library (lights.limitlessled) -ledcontroller==1.0.7 +ledcontroller==1.1.0 # Chromecast bindings (media_player.cast) pychromecast==0.6.12