Add blinkstick support

This commit is contained in:
Alan Bowman 2015-09-29 21:32:28 +01:00
parent 6d53944fa1
commit 047cff6596
3 changed files with 76 additions and 0 deletions

View File

@ -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

View File

@ -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()

View File

@ -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