mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Support for COLOR_TEMP in Homematic dimmers (#31207)
* Support for COLOR_TEMP in Homematic dimmers * Fix lint issues * Added pre-checks * Fix review feedback * Remove unneded code
This commit is contained in:
parent
4332cbe112
commit
df2351b920
@ -63,6 +63,7 @@ HM_DEVICE_TYPES = {
|
|||||||
"IPDimmer",
|
"IPDimmer",
|
||||||
"ColorEffectLight",
|
"ColorEffectLight",
|
||||||
"IPKeySwitchLevel",
|
"IPKeySwitchLevel",
|
||||||
|
"ColdWarmDimmer",
|
||||||
],
|
],
|
||||||
DISCOVER_SENSORS: [
|
DISCOVER_SENSORS: [
|
||||||
"SwitchPowermeter",
|
"SwitchPowermeter",
|
||||||
|
@ -3,11 +3,13 @@ import logging
|
|||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
|
ATTR_COLOR_TEMP,
|
||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
SUPPORT_BRIGHTNESS,
|
SUPPORT_BRIGHTNESS,
|
||||||
SUPPORT_COLOR,
|
SUPPORT_COLOR,
|
||||||
|
SUPPORT_COLOR_TEMP,
|
||||||
SUPPORT_EFFECT,
|
SUPPORT_EFFECT,
|
||||||
Light,
|
Light,
|
||||||
)
|
)
|
||||||
@ -60,6 +62,8 @@ class HMLight(HMDevice, Light):
|
|||||||
features |= SUPPORT_COLOR
|
features |= SUPPORT_COLOR
|
||||||
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
|
||||||
@ -70,6 +74,14 @@ class HMLight(HMDevice, Light):
|
|||||||
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
|
||||||
|
|
||||||
|
@property
|
||||||
|
def color_temp(self):
|
||||||
|
"""Return the color temp in mireds [int]."""
|
||||||
|
if not self.supported_features & SUPPORT_COLOR_TEMP:
|
||||||
|
return None
|
||||||
|
hm_color_temp = self._hmdevice.get_color_temp(self._channel)
|
||||||
|
return self.max_mireds - (self.max_mireds - self.min_mireds) * hm_color_temp
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def effect_list(self):
|
def effect_list(self):
|
||||||
"""Return the list of supported effects."""
|
"""Return the list of supported effects."""
|
||||||
@ -92,7 +104,11 @@ class HMLight(HMDevice, Light):
|
|||||||
if ATTR_BRIGHTNESS in kwargs and self._state == "LEVEL":
|
if ATTR_BRIGHTNESS in kwargs and self._state == "LEVEL":
|
||||||
percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255
|
percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255
|
||||||
self._hmdevice.set_level(percent_bright, self._channel)
|
self._hmdevice.set_level(percent_bright, self._channel)
|
||||||
elif ATTR_HS_COLOR not in kwargs and ATTR_EFFECT not in kwargs:
|
elif (
|
||||||
|
ATTR_HS_COLOR not in kwargs
|
||||||
|
and ATTR_COLOR_TEMP not in kwargs
|
||||||
|
and ATTR_EFFECT not in kwargs
|
||||||
|
):
|
||||||
self._hmdevice.on(self._channel)
|
self._hmdevice.on(self._channel)
|
||||||
|
|
||||||
if ATTR_HS_COLOR in kwargs:
|
if ATTR_HS_COLOR in kwargs:
|
||||||
@ -101,6 +117,11 @@ class HMLight(HMDevice, Light):
|
|||||||
saturation=kwargs[ATTR_HS_COLOR][1] / 100.0,
|
saturation=kwargs[ATTR_HS_COLOR][1] / 100.0,
|
||||||
channel=self._channel,
|
channel=self._channel,
|
||||||
)
|
)
|
||||||
|
if ATTR_COLOR_TEMP in kwargs:
|
||||||
|
hm_temp = (self.max_mireds - kwargs[ATTR_COLOR_TEMP]) / (
|
||||||
|
self.max_mireds - self.min_mireds
|
||||||
|
)
|
||||||
|
self._hmdevice.set_color_temp(hm_temp)
|
||||||
if ATTR_EFFECT in kwargs:
|
if ATTR_EFFECT in kwargs:
|
||||||
self._hmdevice.set_effect(kwargs[ATTR_EFFECT])
|
self._hmdevice.set_effect(kwargs[ATTR_EFFECT])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user