mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
LIFX: disable color features for white-only bulbs (#7742)
The product type is already established in order to decide the Kelvin range so just reuse that information to disable color features for white-only lights. Also change the breathe/pulse effects to be more useful for white-only bulbs. For consistency, color bulbs set to a desaturated (i.e. white-ish) color get the same default treatment as white-only bulbs.
This commit is contained in:
parent
be53cc7068
commit
fce09f624b
@ -54,9 +54,6 @@ ATTR_POWER = 'power'
|
||||
BYTE_MAX = 255
|
||||
SHORT_MAX = 65535
|
||||
|
||||
SUPPORT_LIFX = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR |
|
||||
SUPPORT_XY_COLOR | SUPPORT_TRANSITION | SUPPORT_EFFECT)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Optional(CONF_SERVER, default='0.0.0.0'): cv.string,
|
||||
})
|
||||
@ -229,6 +226,12 @@ class LIFXLight(Light):
|
||||
self.set_power(device.power_level)
|
||||
self.set_color(*device.color)
|
||||
|
||||
@property
|
||||
def lifxwhite(self):
|
||||
"""Return whether this is a white-only bulb."""
|
||||
# https://lan.developer.lifx.com/docs/lifx-products
|
||||
return self.product in [10, 11, 18]
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return the availability of the device."""
|
||||
@ -273,8 +276,7 @@ class LIFXLight(Light):
|
||||
def min_mireds(self):
|
||||
"""Return the coldest color_temp that this light supports."""
|
||||
# The 3 LIFX "White" products supported a limited temperature range
|
||||
# https://lan.developer.lifx.com/docs/lifx-products
|
||||
if self.product in [10, 11, 18]:
|
||||
if self.lifxwhite:
|
||||
kelvin = 6500
|
||||
else:
|
||||
kelvin = 9000
|
||||
@ -284,8 +286,7 @@ class LIFXLight(Light):
|
||||
def max_mireds(self):
|
||||
"""Return the warmest color_temp that this light supports."""
|
||||
# The 3 LIFX "White" products supported a limited temperature range
|
||||
# https://lan.developer.lifx.com/docs/lifx-products
|
||||
if self.product in [10, 11, 18]:
|
||||
if self.lifxwhite:
|
||||
kelvin = 2700
|
||||
else:
|
||||
kelvin = 2500
|
||||
@ -305,12 +306,18 @@ class LIFXLight(Light):
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag supported features."""
|
||||
return SUPPORT_LIFX
|
||||
features = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP |
|
||||
SUPPORT_TRANSITION | SUPPORT_EFFECT)
|
||||
|
||||
if not self.lifxwhite:
|
||||
features |= SUPPORT_RGB_COLOR | SUPPORT_XY_COLOR
|
||||
|
||||
return features
|
||||
|
||||
@property
|
||||
def effect_list(self):
|
||||
"""Return the list of supported effects."""
|
||||
return lifx_effects.effect_list()
|
||||
return lifx_effects.effect_list(self)
|
||||
|
||||
@asyncio.coroutine
|
||||
def update_after_transition(self, now):
|
||||
|
@ -7,7 +7,7 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.components.light import (
|
||||
DOMAIN, ATTR_BRIGHTNESS, ATTR_BRIGHTNESS_PCT, ATTR_COLOR_NAME,
|
||||
ATTR_RGB_COLOR, ATTR_EFFECT, ATTR_TRANSITION,
|
||||
ATTR_RGB_COLOR, ATTR_COLOR_TEMP, ATTR_KELVIN, ATTR_EFFECT, ATTR_TRANSITION,
|
||||
VALID_BRIGHTNESS, VALID_BRIGHTNESS_PCT)
|
||||
from homeassistant.const import (ATTR_ENTITY_ID)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
@ -42,6 +42,8 @@ LIFX_EFFECT_BREATHE_SCHEMA = LIFX_EFFECT_SCHEMA.extend({
|
||||
ATTR_COLOR_NAME: cv.string,
|
||||
ATTR_RGB_COLOR: vol.All(vol.ExactSequence((cv.byte, cv.byte, cv.byte)),
|
||||
vol.Coerce(tuple)),
|
||||
ATTR_COLOR_TEMP: vol.All(vol.Coerce(int), vol.Range(min=1)),
|
||||
ATTR_KELVIN: vol.All(vol.Coerce(int), vol.Range(min=0)),
|
||||
vol.Optional(ATTR_PERIOD, default=1.0):
|
||||
vol.All(vol.Coerce(float), vol.Range(min=0.05)),
|
||||
vol.Optional(ATTR_CYCLES, default=1.0):
|
||||
@ -131,14 +133,21 @@ def default_effect(light, **kwargs):
|
||||
yield from light.hass.services.async_call(DOMAIN, service, data)
|
||||
|
||||
|
||||
def effect_list():
|
||||
"""Return the list of supported effects."""
|
||||
return [
|
||||
SERVICE_EFFECT_COLORLOOP,
|
||||
SERVICE_EFFECT_BREATHE,
|
||||
SERVICE_EFFECT_PULSE,
|
||||
SERVICE_EFFECT_STOP,
|
||||
]
|
||||
def effect_list(light):
|
||||
"""Return the list of supported effects for this light."""
|
||||
if light.lifxwhite:
|
||||
return [
|
||||
SERVICE_EFFECT_BREATHE,
|
||||
SERVICE_EFFECT_PULSE,
|
||||
SERVICE_EFFECT_STOP,
|
||||
]
|
||||
else:
|
||||
return [
|
||||
SERVICE_EFFECT_COLORLOOP,
|
||||
SERVICE_EFFECT_BREATHE,
|
||||
SERVICE_EFFECT_PULSE,
|
||||
SERVICE_EFFECT_STOP,
|
||||
]
|
||||
|
||||
|
||||
class LIFXEffectData(object):
|
||||
@ -230,12 +239,14 @@ class LIFXEffectBreathe(LIFXEffect):
|
||||
cycles = kwargs[ATTR_CYCLES]
|
||||
hsbk, color_changed = light.find_hsbk(**kwargs)
|
||||
|
||||
# Default color is to fully (de)saturate with full brightness
|
||||
# Set default effect color based on current setting
|
||||
if not color_changed:
|
||||
if hsbk[1] > 65536/2:
|
||||
hsbk = [hsbk[0], 0, 65535, 4000]
|
||||
if light.lifxwhite or hsbk[1] < 65536/2:
|
||||
# White: toggle brightness
|
||||
hsbk[2] = 65535 if hsbk[2] < 65536/2 else 0
|
||||
else:
|
||||
hsbk = [hsbk[0], 65535, 65535, hsbk[3]]
|
||||
# Color: fully desaturate with full brightness
|
||||
hsbk = [hsbk[0], 0, 65535, 4000]
|
||||
|
||||
# Start the effect
|
||||
args = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user