mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Merge pull request #459 from auchter/limitlessled-white
Add support for white LimitlessLED devices and multiple bridges
This commit is contained in:
commit
e6cd9a6dc7
@ -19,11 +19,15 @@ configuration.yaml file.
|
|||||||
|
|
||||||
light:
|
light:
|
||||||
platform: limitlessled
|
platform: limitlessled
|
||||||
host: 192.168.1.10
|
bridges:
|
||||||
group_1_name: Living Room
|
- host: 192.168.1.10
|
||||||
group_2_name: Bedroom
|
group_1_name: Living Room
|
||||||
group_3_name: Office
|
group_2_name: Bedroom
|
||||||
group_4_name: Kitchen
|
group_3_name: Office
|
||||||
|
group_3_type: white
|
||||||
|
group_4_name: Kitchen
|
||||||
|
- host: 192.168.1.11
|
||||||
|
group_2_name: Basement
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -33,19 +37,30 @@ from homeassistant.components.light import (Light, ATTR_BRIGHTNESS,
|
|||||||
from homeassistant.util.color import color_RGB_to_xy
|
from homeassistant.util.color import color_RGB_to_xy
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
""" Gets the LimitlessLED lights. """
|
""" Gets the LimitlessLED lights. """
|
||||||
import ledcontroller
|
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 = []
|
lights = []
|
||||||
for i in range(1, 5):
|
for bridge in bridges:
|
||||||
if 'group_%d_name' % (i) in config:
|
for i in range(1, 5):
|
||||||
lights.append(LimitlessLED(led, i, config['group_%d_name' % (i)]))
|
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)
|
add_devices_callback(lights)
|
||||||
|
|
||||||
@ -53,15 +68,57 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
class LimitlessLED(Light):
|
class LimitlessLED(Light):
|
||||||
""" Represents a LimitlessLED light """
|
""" Represents a LimitlessLED light """
|
||||||
|
|
||||||
def __init__(self, led, group, name):
|
@staticmethod
|
||||||
self.led = led
|
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.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.
|
# 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._name = name or DEVICE_DEFAULT_NAME
|
||||||
self._state = False
|
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._brightness = 100
|
||||||
self._xy_color = color_RGB_to_xy(255, 255, 255)
|
self._xy_color = color_RGB_to_xy(255, 255, 255)
|
||||||
|
|
||||||
@ -87,16 +144,6 @@ class LimitlessLED(Light):
|
|||||||
((0xE6, 0xE6, 0xFA), 'lavendar'),
|
((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
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
return self._brightness
|
return self._brightness
|
||||||
@ -117,11 +164,6 @@ class LimitlessLED(Light):
|
|||||||
# First candidate in the sorted list is closest to desired color:
|
# First candidate in the sorted list is closest to desired color:
|
||||||
return sorted(candidates)[0][1]
|
return sorted(candidates)[0][1]
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self):
|
|
||||||
""" True if device is on. """
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
""" Turn the device on. """
|
""" Turn the device on. """
|
||||||
self._state = True
|
self._state = True
|
||||||
@ -132,12 +174,21 @@ class LimitlessLED(Light):
|
|||||||
if ATTR_XY_COLOR in kwargs:
|
if ATTR_XY_COLOR in kwargs:
|
||||||
self._xy_color = kwargs[ATTR_XY_COLOR]
|
self._xy_color = kwargs[ATTR_XY_COLOR]
|
||||||
|
|
||||||
self.led.set_color(self._xy_to_led_color(self._xy_color), self.group)
|
self.pool.execute(self.controller_id, "set_color",
|
||||||
self.led.set_brightness(self._brightness / 255.0, self.group)
|
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()
|
self.update_ha_state()
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
|
||||||
""" Turn the device off. """
|
class WhiteLimitlessLED(LimitlessLED):
|
||||||
self._state = False
|
""" Represents a White LimitlessLED light """
|
||||||
self.led.off(self.group)
|
|
||||||
|
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()
|
self.update_ha_state()
|
||||||
|
@ -14,7 +14,7 @@ astral==0.8.1
|
|||||||
phue==0.8
|
phue==0.8
|
||||||
|
|
||||||
# Limitlessled/Easybulb/Milight library (lights.limitlessled)
|
# Limitlessled/Easybulb/Milight library (lights.limitlessled)
|
||||||
ledcontroller==1.0.7
|
ledcontroller==1.1.0
|
||||||
|
|
||||||
# Chromecast bindings (media_player.cast)
|
# Chromecast bindings (media_player.cast)
|
||||||
pychromecast==0.6.12
|
pychromecast==0.6.12
|
||||||
|
Loading…
x
Reference in New Issue
Block a user