parent
9bb94a4512
commit
b07d887d77
1 changed files with 11 additions and 1 deletions
|
@ -23,6 +23,7 @@ REQUIREMENTS = ['https://github.com/Danielhiversen/flux_led/archive/0.8.zip'
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_AUTOMATIC_ADD = 'automatic_add'
|
||||
ATTR_MODE = 'mode'
|
||||
|
||||
DOMAIN = 'flux_led'
|
||||
|
||||
|
@ -31,6 +32,8 @@ SUPPORT_FLUX_LED = (SUPPORT_BRIGHTNESS | SUPPORT_EFFECT |
|
|||
|
||||
DEVICE_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(ATTR_MODE, default='rgbw'):
|
||||
vol.All(cv.string, vol.In(['rgbw', 'rgb'])),
|
||||
})
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
|
@ -48,6 +51,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
device = {}
|
||||
device['name'] = device_config[CONF_NAME]
|
||||
device['ipaddr'] = ipaddr
|
||||
device[ATTR_MODE] = device_config[ATTR_MODE]
|
||||
light = FluxLight(device)
|
||||
if light.is_valid:
|
||||
lights.append(light)
|
||||
|
@ -65,6 +69,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
if ipaddr in light_ips:
|
||||
continue
|
||||
device['name'] = device['id'] + " " + ipaddr
|
||||
device[ATTR_MODE] = 'rgbw'
|
||||
light = FluxLight(device)
|
||||
if light.is_valid:
|
||||
lights.append(light)
|
||||
|
@ -82,6 +87,7 @@ class FluxLight(Light):
|
|||
|
||||
self._name = device['name']
|
||||
self._ipaddr = device['ipaddr']
|
||||
self._mode = device[ATTR_MODE]
|
||||
self.is_valid = True
|
||||
self._bulb = None
|
||||
try:
|
||||
|
@ -132,7 +138,11 @@ class FluxLight(Light):
|
|||
if rgb:
|
||||
self._bulb.setRgb(*tuple(rgb))
|
||||
elif brightness:
|
||||
self._bulb.setWarmWhite255(brightness)
|
||||
if self._mode == 'rgbw':
|
||||
self._bulb.setWarmWhite255(brightness)
|
||||
elif self._mode == 'rgb':
|
||||
(red, green, blue) = self._bulb.getRgb()
|
||||
self._bulb.setRgb(red, green, blue, brightness=brightness)
|
||||
elif effect == EFFECT_RANDOM:
|
||||
self._bulb.setRgb(random.randrange(0, 255),
|
||||
random.randrange(0, 255),
|
||||
|
|
Loading…
Add table
Reference in a new issue