From 6d53944fa1f1c0fdb743f748ac85fbb59c6d1a72 Mon Sep 17 00:00:00 2001 From: Alan Bowman Date: Sun, 4 Oct 2015 20:28:11 +0100 Subject: [PATCH 1/3] Support RGB colors --- homeassistant/components/light/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 8d09910093b..c1b1579b4b5 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -246,6 +246,7 @@ def setup(hass, config): rgb_color = dat.get(ATTR_RGB_COLOR) if len(rgb_color) == 3: + params[ATTR_RGB_COLOR] = [int(val) for val in rgb_color] params[ATTR_XY_COLOR] = \ color_util.color_RGB_to_xy(int(rgb_color[0]), int(rgb_color[1]), From 047cff6596f50b29b3885eb88a44c91627645775 Mon Sep 17 00:00:00 2001 From: Alan Bowman Date: Tue, 29 Sep 2015 21:32:28 +0100 Subject: [PATCH 2/3] Add blinkstick support --- .coveragerc | 1 + .../components/light/blinksticklight.py | 72 +++++++++++++++++++ requirements_all.txt | 3 + 3 files changed, 76 insertions(+) create mode 100644 homeassistant/components/light/blinksticklight.py diff --git a/.coveragerc b/.coveragerc index 95816fa55a9..1cdbb2b4838 100644 --- a/.coveragerc +++ b/.coveragerc @@ -44,6 +44,7 @@ omit = homeassistant/components/keyboard.py homeassistant/components/light/hue.py homeassistant/components/light/limitlessled.py + homeassistant/components/light/blinksticklight.py homeassistant/components/media_player/cast.py homeassistant/components/media_player/denon.py homeassistant/components/media_player/itunes.py diff --git a/homeassistant/components/light/blinksticklight.py b/homeassistant/components/light/blinksticklight.py new file mode 100644 index 00000000000..364b5f030c6 --- /dev/null +++ b/homeassistant/components/light/blinksticklight.py @@ -0,0 +1,72 @@ +""" +homeassistant.components.light.blinksticklight +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Support for Blinkstick lights. +""" + +from blinkstick import blinkstick +import logging + +_LOGGER = logging.getLogger(__name__) + +from homeassistant.components.light import (Light, ATTR_RGB_COLOR) + +REQUIREMENTS = ["blinkstick==1.1.7"] +DEPENDENCIES = [] + +# pylint: disable=unused-argument + + +def setup_platform(hass, config, add_devices_callback, discovery_info=None): + """ Add device specified by serial number """ + stick = blinkstick.find_by_serial(config['serial']) + + add_devices_callback([BlinkStickLight(stick, config['name'])]) + + +class BlinkStickLight(Light): + """ Represents a BlinkStick light """ + + def __init__(self, stick, name): + """ Initialise """ + self._stick = stick + self._name = name + self._serial = stick.get_serial() + self._rgb_color = stick.get_color() + + @property + def should_poll(self): + return True + + @property + def name(self): + return self._name + + @property + def rgb_color(self): + """ Read back the color of the light """ + return self._rgb_color + + @property + def is_on(self): + """ Check whether any of the LEDs colors are non-zero """ + return sum(self._rgb_color) > 0 + + def update(self): + """ Read back the device state """ + self._rgb_color = self._stick.get_color() + + def turn_on(self, **kwargs): + """ Turn the device on. """ + if ATTR_RGB_COLOR in kwargs: + self._rgb_color = kwargs[ATTR_RGB_COLOR] + else: + self._rgb_color = [255, 255, 255] + + self._stick.set_color(red=self._rgb_color[0], + green=self._rgb_color[1], + blue=self._rgb_color[2]) + + def turn_off(self, **kwargs): + """ Turn the device off """ + self._stick.turn_off() diff --git a/requirements_all.txt b/requirements_all.txt index 4610100b161..1921f975996 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -137,3 +137,6 @@ SoCo==0.11.1 # PlexAPI (media_player.plex) https://github.com/adrienbrault/python-plexapi/archive/df2d0847e801d6d5cda920326d693cf75f304f1a.zip#python-plexapi==1.0.2 + +# Blinkstick +blinkstick==1.1.7 From 9d4aa7e519236f4da326a92f00114dc842d52bef Mon Sep 17 00:00:00 2001 From: Alan Bowman Date: Wed, 7 Oct 2015 13:58:21 +0100 Subject: [PATCH 3/3] Update tests for RGB color support --- tests/components/test_light.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/components/test_light.py b/tests/components/test_light.py index 515b79b6fc0..156ba51e59a 100644 --- a/tests/components/test_light.py +++ b/tests/components/test_light.py @@ -152,9 +152,13 @@ class TestLight(unittest.TestCase): data) method, data = dev2.last_call('turn_on') - self.assertEqual( - {light.ATTR_XY_COLOR: color_util.color_RGB_to_xy(255, 255, 255)}, - data) + self.assertEquals( + data[light.ATTR_XY_COLOR], + color_util.color_RGB_to_xy(255, 255, 255)) + + self.assertEquals( + data[light.ATTR_RGB_COLOR], + [255, 255, 255]) method, data = dev3.last_call('turn_on') self.assertEqual({light.ATTR_XY_COLOR: [.4, .6]}, data)