mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Migrate homematic light to color_mode (#69267)
This commit is contained in:
parent
1a9420dda0
commit
7b18d511cc
@ -7,9 +7,9 @@ from homeassistant.components.light import (
|
|||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
SUPPORT_BRIGHTNESS,
|
COLOR_MODE_BRIGHTNESS,
|
||||||
SUPPORT_COLOR,
|
COLOR_MODE_COLOR_TEMP,
|
||||||
SUPPORT_COLOR_TEMP,
|
COLOR_MODE_HS,
|
||||||
SUPPORT_EFFECT,
|
SUPPORT_EFFECT,
|
||||||
SUPPORT_TRANSITION,
|
SUPPORT_TRANSITION,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
@ -21,8 +21,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
|||||||
from .const import ATTR_DISCOVER_DEVICES
|
from .const import ATTR_DISCOVER_DEVICES
|
||||||
from .entity import HMDevice
|
from .entity import HMDevice
|
||||||
|
|
||||||
SUPPORT_HOMEMATIC = SUPPORT_BRIGHTNESS
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(
|
def setup_platform(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -62,22 +60,40 @@ class HMLight(HMDevice, LightEntity):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def color_mode(self) -> str:
|
||||||
"""Flag supported features."""
|
"""Return the color mode of the light."""
|
||||||
features = SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
|
if "COLOR" in self._hmdevice.WRITENODE:
|
||||||
|
return COLOR_MODE_HS
|
||||||
|
if hasattr(self._hmdevice, "get_color_temp"):
|
||||||
|
return COLOR_MODE_COLOR_TEMP
|
||||||
|
return COLOR_MODE_BRIGHTNESS
|
||||||
|
|
||||||
|
@property
|
||||||
|
def supported_color_modes(self) -> set[str] | None:
|
||||||
|
"""Flag supported color modes."""
|
||||||
|
color_modes = set()
|
||||||
|
|
||||||
if "COLOR" in self._hmdevice.WRITENODE:
|
if "COLOR" in self._hmdevice.WRITENODE:
|
||||||
features |= SUPPORT_COLOR
|
color_modes.add(COLOR_MODE_HS)
|
||||||
|
if hasattr(self._hmdevice, "get_color_temp"):
|
||||||
|
color_modes.add(COLOR_MODE_COLOR_TEMP)
|
||||||
|
if not color_modes:
|
||||||
|
color_modes.add(COLOR_MODE_BRIGHTNESS)
|
||||||
|
|
||||||
|
return color_modes
|
||||||
|
|
||||||
|
@property
|
||||||
|
def supported_features(self):
|
||||||
|
"""Flag supported features."""
|
||||||
|
features = SUPPORT_TRANSITION
|
||||||
if "PROGRAM" in self._hmdevice.WRITENODE:
|
if "PROGRAM" in self._hmdevice.WRITENODE:
|
||||||
features |= SUPPORT_EFFECT
|
features |= SUPPORT_EFFECT
|
||||||
if hasattr(self._hmdevice, "get_color_temp"):
|
|
||||||
features |= SUPPORT_COLOR_TEMP
|
|
||||||
return features
|
return features
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hs_color(self):
|
def hs_color(self):
|
||||||
"""Return the hue and saturation color value [float, float]."""
|
"""Return the hue and saturation color value [float, float]."""
|
||||||
if not self.supported_features & SUPPORT_COLOR:
|
if COLOR_MODE_HS not in self.supported_color_modes:
|
||||||
return None
|
return None
|
||||||
hue, sat = self._hmdevice.get_hs_color(self._channel)
|
hue, sat = self._hmdevice.get_hs_color(self._channel)
|
||||||
return hue * 360.0, sat * 100.0
|
return hue * 360.0, sat * 100.0
|
||||||
@ -85,7 +101,7 @@ class HMLight(HMDevice, LightEntity):
|
|||||||
@property
|
@property
|
||||||
def color_temp(self):
|
def color_temp(self):
|
||||||
"""Return the color temp in mireds [int]."""
|
"""Return the color temp in mireds [int]."""
|
||||||
if not self.supported_features & SUPPORT_COLOR_TEMP:
|
if COLOR_MODE_COLOR_TEMP not in self.supported_color_modes:
|
||||||
return None
|
return None
|
||||||
hm_color_temp = self._hmdevice.get_color_temp(self._channel)
|
hm_color_temp = self._hmdevice.get_color_temp(self._channel)
|
||||||
return self.max_mireds - (self.max_mireds - self.min_mireds) * hm_color_temp
|
return self.max_mireds - (self.max_mireds - self.min_mireds) * hm_color_temp
|
||||||
@ -119,7 +135,7 @@ class HMLight(HMDevice, LightEntity):
|
|||||||
):
|
):
|
||||||
self._hmdevice.on(self._channel)
|
self._hmdevice.on(self._channel)
|
||||||
|
|
||||||
if ATTR_HS_COLOR in kwargs and self.supported_features & SUPPORT_COLOR:
|
if ATTR_HS_COLOR in kwargs:
|
||||||
self._hmdevice.set_hs_color(
|
self._hmdevice.set_hs_color(
|
||||||
hue=kwargs[ATTR_HS_COLOR][0] / 360.0,
|
hue=kwargs[ATTR_HS_COLOR][0] / 360.0,
|
||||||
saturation=kwargs[ATTR_HS_COLOR][1] / 100.0,
|
saturation=kwargs[ATTR_HS_COLOR][1] / 100.0,
|
||||||
@ -146,7 +162,7 @@ class HMLight(HMDevice, LightEntity):
|
|||||||
self._state = "LEVEL"
|
self._state = "LEVEL"
|
||||||
self._data[self._state] = None
|
self._data[self._state] = None
|
||||||
|
|
||||||
if self.supported_features & SUPPORT_COLOR:
|
if COLOR_MODE_HS in self.supported_color_modes:
|
||||||
self._data.update({"COLOR": None})
|
self._data.update({"COLOR": None})
|
||||||
if self.supported_features & SUPPORT_EFFECT:
|
if self.supported_features & SUPPORT_EFFECT:
|
||||||
self._data.update({"PROGRAM": None})
|
self._data.update({"PROGRAM": None})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user