mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Migrate lifx light to color_mode (#69420)
* Migrate lifx light to color_mode * Update LIFXColor to support both hs and color_temp * Apply suggestions from code review Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update light.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
9f43fca586
commit
59c6282c6c
@ -29,14 +29,11 @@ from homeassistant.components.light import (
|
|||||||
COLOR_GROUP,
|
COLOR_GROUP,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
LIGHT_TURN_ON_SCHEMA,
|
LIGHT_TURN_ON_SCHEMA,
|
||||||
SUPPORT_BRIGHTNESS,
|
|
||||||
SUPPORT_COLOR,
|
|
||||||
SUPPORT_COLOR_TEMP,
|
|
||||||
SUPPORT_EFFECT,
|
|
||||||
SUPPORT_TRANSITION,
|
|
||||||
VALID_BRIGHTNESS,
|
VALID_BRIGHTNESS,
|
||||||
VALID_BRIGHTNESS_PCT,
|
VALID_BRIGHTNESS_PCT,
|
||||||
|
ColorMode,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
|
LightEntityFeature,
|
||||||
preprocess_turn_on_alternatives,
|
preprocess_turn_on_alternatives,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -506,6 +503,8 @@ def convert_16_to_8(value):
|
|||||||
class LIFXLight(LightEntity):
|
class LIFXLight(LightEntity):
|
||||||
"""Representation of a LIFX light."""
|
"""Representation of a LIFX light."""
|
||||||
|
|
||||||
|
_attr_supported_features = LightEntityFeature.TRANSITION | LightEntityFeature.EFFECT
|
||||||
|
|
||||||
def __init__(self, bulb, effects_conductor):
|
def __init__(self, bulb, effects_conductor):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
self.bulb = bulb
|
self.bulb = bulb
|
||||||
@ -577,15 +576,17 @@ class LIFXLight(LightEntity):
|
|||||||
return math.ceil(color_util.color_temperature_kelvin_to_mired(kelvin))
|
return math.ceil(color_util.color_temperature_kelvin_to_mired(kelvin))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def color_mode(self) -> ColorMode:
|
||||||
"""Flag supported features."""
|
"""Return the color mode of the light."""
|
||||||
support = SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | SUPPORT_EFFECT
|
|
||||||
|
|
||||||
bulb_features = lifx_features(self.bulb)
|
bulb_features = lifx_features(self.bulb)
|
||||||
if bulb_features["min_kelvin"] != bulb_features["max_kelvin"]:
|
if bulb_features["min_kelvin"] != bulb_features["max_kelvin"]:
|
||||||
support |= SUPPORT_COLOR_TEMP
|
return ColorMode.COLOR_TEMP
|
||||||
|
return ColorMode.BRIGHTNESS
|
||||||
|
|
||||||
return support
|
@property
|
||||||
|
def supported_color_modes(self) -> set[ColorMode]:
|
||||||
|
"""Flag supported color modes."""
|
||||||
|
return {self.color_mode}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
@ -735,11 +736,17 @@ class LIFXColor(LIFXLight):
|
|||||||
"""Representation of a color LIFX light."""
|
"""Representation of a color LIFX light."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def color_mode(self) -> ColorMode:
|
||||||
"""Flag supported features."""
|
"""Return the color mode of the light."""
|
||||||
support = super().supported_features
|
sat = self.bulb.color[1]
|
||||||
support |= SUPPORT_COLOR
|
if sat:
|
||||||
return support
|
return ColorMode.HS
|
||||||
|
return ColorMode.COLOR_TEMP
|
||||||
|
|
||||||
|
@property
|
||||||
|
def supported_color_modes(self) -> set[ColorMode]:
|
||||||
|
"""Flag supported color modes."""
|
||||||
|
return {ColorMode.COLOR_TEMP, ColorMode.HS}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def effect_list(self):
|
def effect_list(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user