mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Add support color and brightness for flux light (#2750)
This commit is contained in:
parent
8daaee702b
commit
689939ab9d
@ -9,11 +9,12 @@ import logging
|
|||||||
import socket
|
import socket
|
||||||
import voluptuous as vol
|
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
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['https://github.com/Danielhiversen/flux_led/archive/0.3.zip'
|
REQUIREMENTS = ['https://github.com/Danielhiversen/flux_led/archive/0.5.zip'
|
||||||
'#flux_led==0.3']
|
'#flux_led==0.5']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
DOMAIN = "flux_led"
|
DOMAIN = "flux_led"
|
||||||
@ -37,7 +38,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
light_ips = []
|
light_ips = []
|
||||||
for ipaddr, device_config in config["devices"].items():
|
for ipaddr, device_config in config["devices"].items():
|
||||||
device = {}
|
device = {}
|
||||||
device['id'] = device_config[ATTR_NAME]
|
device['name'] = device_config[ATTR_NAME]
|
||||||
device['ipaddr'] = ipaddr
|
device['ipaddr'] = ipaddr
|
||||||
light = FluxLight(device)
|
light = FluxLight(device)
|
||||||
if light.is_valid:
|
if light.is_valid:
|
||||||
@ -50,11 +51,14 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
|
|
||||||
# Find the bulbs on the LAN
|
# Find the bulbs on the LAN
|
||||||
scanner = flux_led.BulbScanner()
|
scanner = flux_led.BulbScanner()
|
||||||
scanner.scan(timeout=20)
|
scanner.scan(timeout=10)
|
||||||
for device in scanner.getBulbInfo():
|
for device in scanner.getBulbInfo():
|
||||||
light = FluxLight(device)
|
|
||||||
ipaddr = device['ipaddr']
|
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)
|
lights.append(light)
|
||||||
light_ips.append(ipaddr)
|
light_ips.append(ipaddr)
|
||||||
|
|
||||||
@ -69,7 +73,7 @@ class FluxLight(Light):
|
|||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
import flux_led
|
import flux_led
|
||||||
|
|
||||||
self._name = device['id']
|
self._name = device['name']
|
||||||
self._ipaddr = device['ipaddr']
|
self._ipaddr = device['ipaddr']
|
||||||
self.is_valid = True
|
self.is_valid = True
|
||||||
self._bulb = None
|
self._bulb = None
|
||||||
@ -96,9 +100,26 @@ class FluxLight(Light):
|
|||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
return self._bulb.isOn()
|
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):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn the specified or all lights on."""
|
"""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):
|
def turn_off(self, **kwargs):
|
||||||
"""Turn the specified or all lights off."""
|
"""Turn the specified or all lights off."""
|
||||||
|
@ -101,7 +101,7 @@ hikvision==0.4
|
|||||||
# http://github.com/mala-zaba/Adafruit_Python_DHT/archive/4101340de8d2457dd194bca1e8d11cbfc237e919.zip#Adafruit_DHT==1.1.0
|
# http://github.com/mala-zaba/Adafruit_Python_DHT/archive/4101340de8d2457dd194bca1e8d11cbfc237e919.zip#Adafruit_DHT==1.1.0
|
||||||
|
|
||||||
# homeassistant.components.light.flux_led
|
# 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
|
# homeassistant.components.switch.dlink
|
||||||
https://github.com/LinuxChristian/pyW215/archive/v0.1.1.zip#pyW215==0.1.1
|
https://github.com/LinuxChristian/pyW215/archive/v0.1.1.zip#pyW215==0.1.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user