Skip to content

Commit

Permalink
Add support color and brightness for flux light (home-assistant#2750)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielhiversen authored and balloob committed Aug 8, 2016
1 parent 8daaee7 commit 689939a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
39 changes: 30 additions & 9 deletions homeassistant/components/light/flux_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import socket
import voluptuous as vol

from homeassistant.components.light import Light
from homeassistant.components.light import (ATTR_BRIGHTNESS, ATTR_RGB_COLOR,
Light)
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['https://github.com/Danielhiversen/flux_led/archive/0.3.zip'
'#flux_led==0.3']
REQUIREMENTS = ['https://github.com/Danielhiversen/flux_led/archive/0.5.zip'
'#flux_led==0.5']

_LOGGER = logging.getLogger(__name__)
DOMAIN = "flux_led"
Expand All @@ -37,7 +38,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
light_ips = []
for ipaddr, device_config in config["devices"].items():
device = {}
device['id'] = device_config[ATTR_NAME]
device['name'] = device_config[ATTR_NAME]
device['ipaddr'] = ipaddr
light = FluxLight(device)
if light.is_valid:
Expand All @@ -50,11 +51,14 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):

# Find the bulbs on the LAN
scanner = flux_led.BulbScanner()
scanner.scan(timeout=20)
scanner.scan(timeout=10)
for device in scanner.getBulbInfo():
light = FluxLight(device)
ipaddr = device['ipaddr']
if light.is_valid and ipaddr not in light_ips:
if ipaddr in light_ips:
continue
device['name'] = device['id'] + " " + ipaddr
light = FluxLight(device)
if light.is_valid:
lights.append(light)
light_ips.append(ipaddr)

Expand All @@ -69,7 +73,7 @@ def __init__(self, device):
"""Initialize the light."""
import flux_led

self._name = device['id']
self._name = device['name']
self._ipaddr = device['ipaddr']
self.is_valid = True
self._bulb = None
Expand All @@ -96,9 +100,26 @@ def is_on(self):
"""Return true if device is on."""
return self._bulb.isOn()

@property
def brightness(self):
"""Return the brightness of this light between 0..255."""
return self._bulb.getWarmWhite255()

@property
def rgb_color(self):
"""Return the color property."""
return self._bulb.getRgb()

def turn_on(self, **kwargs):
"""Turn the specified or all lights on."""
self._bulb.turnOn()
rgb = kwargs.get(ATTR_RGB_COLOR)
brightness = kwargs.get(ATTR_BRIGHTNESS)
if rgb:
self._bulb.setRgb(*tuple(rgb))
elif brightness:
self._bulb.setWarmWhite255(brightness)
else:
self._bulb.turnOn()

def turn_off(self, **kwargs):
"""Turn the specified or all lights off."""
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ hikvision==0.4
# http://github.com/mala-zaba/Adafruit_Python_DHT/archive/4101340de8d2457dd194bca1e8d11cbfc237e919.zip#Adafruit_DHT==1.1.0

# homeassistant.components.light.flux_led
https://github.com/Danielhiversen/flux_led/archive/0.3.zip#flux_led==0.3
https://github.com/Danielhiversen/flux_led/archive/0.5.zip#flux_led==0.5

# homeassistant.components.switch.dlink
https://github.com/LinuxChristian/pyW215/archive/v0.1.1.zip#pyW215==0.1.1
Expand Down

0 comments on commit 689939a

Please sign in to comment.