Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions homeassistant/components/light/flux_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

from homeassistant.const import CONF_DEVICES, CONF_NAME, CONF_PROTOCOL
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_EFFECT, EFFECT_COLORLOOP,
EFFECT_RANDOM, SUPPORT_BRIGHTNESS, SUPPORT_EFFECT,
SUPPORT_COLOR, Light, PLATFORM_SCHEMA)
ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_EFFECT, ATTR_WHITE_VALUE,
EFFECT_COLORLOOP, EFFECT_RANDOM, SUPPORT_BRIGHTNESS, SUPPORT_EFFECT,
SUPPORT_COLOR, SUPPORT_WHITE_VALUE, Light, PLATFORM_SCHEMA)
import homeassistant.helpers.config_validation as cv
import homeassistant.util.color as color_util

Expand Down Expand Up @@ -191,8 +191,16 @@ def hs_color(self):
@property
def supported_features(self):
"""Flag supported features."""
if self._mode is MODE_RGBW:
return SUPPORT_FLUX_LED | SUPPORT_WHITE_VALUE

return SUPPORT_FLUX_LED

@property
def white_value(self):
"""Return the white value of this light between 0..255."""
return self._bulb.getRgbw()[3]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the light entity will request the white_value even if not SUPPORT_WHITE_VALUE. Will this raise an error ?

Copy link
Copy Markdown
Contributor Author

@oblogic7 oblogic7 May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retrieving index 3 should not directly result in an error because the flux_led library will always return something on that index even if None. So it would depend on how the code calling white_level handles the values. I can add a sanity check if None or non integer values are not supported.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's None, then it's fine as that is the expected return value for "no value"


@property
def effect_list(self):
"""Return the list of supported effects."""
Expand All @@ -212,24 +220,31 @@ def turn_on(self, **kwargs):

brightness = kwargs.get(ATTR_BRIGHTNESS)
effect = kwargs.get(ATTR_EFFECT)
white = kwargs.get(ATTR_WHITE_VALUE)

# color change only
if rgb is not None:
self._bulb.setRgb(*tuple(rgb), brightness=self.brightness)

if rgb is not None and brightness is not None:
self._bulb.setRgb(*tuple(rgb), brightness=brightness)
elif rgb is not None:
self._bulb.setRgb(*tuple(rgb))
# brightness change only
elif brightness is not None:
if self._mode == MODE_RGBW:
self._bulb.setWarmWhite255(brightness)
elif self._mode == MODE_RGB:
(red, green, blue) = self._bulb.getRgb()
self._bulb.setRgb(red, green, blue, brightness=brightness)
(red, green, blue) = self._bulb.getRgb()
self._bulb.setRgb(red, green, blue, brightness=brightness)

# random color effect
elif effect == EFFECT_RANDOM:
self._bulb.setRgb(random.randint(0, 255),
random.randint(0, 255),
random.randint(0, 255))

# effect selection
elif effect in EFFECT_MAP:
self._bulb.setPresetPattern(EFFECT_MAP[effect], 50)

# white change only
elif white is not None:
self._bulb.setWarmWhite255(white)

def turn_off(self, **kwargs):
"""Turn the specified or all lights off."""
self._bulb.turnOff()
Expand Down