From 67ca0038be865354c290579f70f05ac43878050e Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 6 Apr 2022 15:04:19 +0200 Subject: [PATCH 1/4] Migrate lifx light to color_mode --- homeassistant/components/lifx/light.py | 35 +++++++++++++++----------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/lifx/light.py b/homeassistant/components/lifx/light.py index 323bec3f1de547..5a22d3203f9335 100644 --- a/homeassistant/components/lifx/light.py +++ b/homeassistant/components/lifx/light.py @@ -25,11 +25,11 @@ ATTR_TRANSITION, ATTR_XY_COLOR, COLOR_GROUP, + COLOR_MODE_BRIGHTNESS, + COLOR_MODE_COLOR_TEMP, + COLOR_MODE_HS, DOMAIN, LIGHT_TURN_ON_SCHEMA, - SUPPORT_BRIGHTNESS, - SUPPORT_COLOR, - SUPPORT_COLOR_TEMP, SUPPORT_EFFECT, SUPPORT_TRANSITION, VALID_BRIGHTNESS, @@ -496,6 +496,8 @@ def convert_16_to_8(value): class LIFXLight(LightEntity): """Representation of a LIFX light.""" + _attr_supported_features = SUPPORT_TRANSITION | SUPPORT_EFFECT + def __init__(self, bulb, effects_conductor): """Initialize the light.""" self.bulb = bulb @@ -567,15 +569,17 @@ def max_mireds(self): return math.ceil(color_util.color_temperature_kelvin_to_mired(kelvin)) @property - def supported_features(self): - """Flag supported features.""" - support = SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | SUPPORT_EFFECT - + def color_mode(self) -> str: + """Return the color mode of the light.""" bulb_features = lifx_features(self.bulb) if bulb_features["min_kelvin"] != bulb_features["max_kelvin"]: - support |= SUPPORT_COLOR_TEMP + return COLOR_MODE_COLOR_TEMP + return COLOR_MODE_BRIGHTNESS - return support + @property + def supported_color_modes(self) -> set[str] | None: + """Flag supported color modes.""" + return {self.color_mode} @property def brightness(self): @@ -725,11 +729,14 @@ class LIFXColor(LIFXLight): """Representation of a color LIFX light.""" @property - def supported_features(self): - """Flag supported features.""" - support = super().supported_features - support |= SUPPORT_COLOR - return support + def color_mode(self) -> str: + """Return the color mode of the light.""" + return COLOR_MODE_HS + + @property + def supported_color_modes(self) -> set[str] | None: + """Flag supported color modes.""" + return {self.color_mode} @property def effect_list(self): From 141655a930cdb4f138069575249cddddd2fb58fa Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 26 Apr 2022 16:36:49 +0200 Subject: [PATCH 2/4] Update LIFXColor to support both hs and color_temp --- homeassistant/components/lifx/light.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/lifx/light.py b/homeassistant/components/lifx/light.py index 5a22d3203f9335..392bd2c64f6aae 100644 --- a/homeassistant/components/lifx/light.py +++ b/homeassistant/components/lifx/light.py @@ -25,15 +25,13 @@ ATTR_TRANSITION, ATTR_XY_COLOR, COLOR_GROUP, - COLOR_MODE_BRIGHTNESS, - COLOR_MODE_COLOR_TEMP, - COLOR_MODE_HS, DOMAIN, LIGHT_TURN_ON_SCHEMA, SUPPORT_EFFECT, SUPPORT_TRANSITION, VALID_BRIGHTNESS, VALID_BRIGHTNESS_PCT, + ColorMode, LightEntity, preprocess_turn_on_alternatives, ) @@ -573,8 +571,8 @@ def color_mode(self) -> str: """Return the color mode of the light.""" bulb_features = lifx_features(self.bulb) if bulb_features["min_kelvin"] != bulb_features["max_kelvin"]: - return COLOR_MODE_COLOR_TEMP - return COLOR_MODE_BRIGHTNESS + return ColorMode.COLOR_TEMP + return ColorMode.BRIGHTNESS @property def supported_color_modes(self) -> set[str] | None: @@ -731,12 +729,15 @@ class LIFXColor(LIFXLight): @property def color_mode(self) -> str: """Return the color mode of the light.""" - return COLOR_MODE_HS + sat = self.bulb.color[1] + if sat: + return ColorMode.HS + return ColorMode.COLOR_TEMP @property def supported_color_modes(self) -> set[str] | None: """Flag supported color modes.""" - return {self.color_mode} + return {ColorMode.COLOR_TEMP, ColorMode.HS} @property def effect_list(self): From fe792337fe7cf19fdebbdadc290782a959350f48 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 27 Apr 2022 16:55:22 +0200 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- homeassistant/components/lifx/light.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/lifx/light.py b/homeassistant/components/lifx/light.py index 392bd2c64f6aae..a791efedec2207 100644 --- a/homeassistant/components/lifx/light.py +++ b/homeassistant/components/lifx/light.py @@ -494,7 +494,7 @@ def convert_16_to_8(value): class LIFXLight(LightEntity): """Representation of a LIFX light.""" - _attr_supported_features = SUPPORT_TRANSITION | SUPPORT_EFFECT + _attr_supported_features = LightEntityFeature.TRANSITION | LightEntityFeature.EFFECT def __init__(self, bulb, effects_conductor): """Initialize the light.""" @@ -567,7 +567,7 @@ def max_mireds(self): return math.ceil(color_util.color_temperature_kelvin_to_mired(kelvin)) @property - def color_mode(self) -> str: + def color_mode(self) -> ColorMode: """Return the color mode of the light.""" bulb_features = lifx_features(self.bulb) if bulb_features["min_kelvin"] != bulb_features["max_kelvin"]: @@ -575,7 +575,7 @@ def color_mode(self) -> str: return ColorMode.BRIGHTNESS @property - def supported_color_modes(self) -> set[str] | None: + def supported_color_modes(self) -> set[ColorMode]: """Flag supported color modes.""" return {self.color_mode} @@ -727,7 +727,7 @@ class LIFXColor(LIFXLight): """Representation of a color LIFX light.""" @property - def color_mode(self) -> str: + def color_mode(self) -> ColorMode: """Return the color mode of the light.""" sat = self.bulb.color[1] if sat: @@ -735,7 +735,7 @@ def color_mode(self) -> str: return ColorMode.COLOR_TEMP @property - def supported_color_modes(self) -> set[str] | None: + def supported_color_modes(self) -> set[ColorMode]: """Flag supported color modes.""" return {ColorMode.COLOR_TEMP, ColorMode.HS} From f67864403e058944f5287d965e561cd786df1637 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 27 Apr 2022 18:10:42 +0200 Subject: [PATCH 4/4] Update light.py --- homeassistant/components/lifx/light.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/lifx/light.py b/homeassistant/components/lifx/light.py index a791efedec2207..77a4820db520c3 100644 --- a/homeassistant/components/lifx/light.py +++ b/homeassistant/components/lifx/light.py @@ -27,12 +27,11 @@ COLOR_GROUP, DOMAIN, LIGHT_TURN_ON_SCHEMA, - SUPPORT_EFFECT, - SUPPORT_TRANSITION, VALID_BRIGHTNESS, VALID_BRIGHTNESS_PCT, ColorMode, LightEntity, + LightEntityFeature, preprocess_turn_on_alternatives, ) from homeassistant.config_entries import ConfigEntry