mirror of https://github.com/home-assistant/core
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",
|
||||
"ColorEffectLight",
|
||||
"IPKeySwitchLevel",
|
||||
"ColdWarmDimmer",
|
||||
],
|
||||
DISCOVER_SENSORS: [
|
||||
"SwitchPowermeter",
|
||||
|
|
|
@ -3,11 +3,13 @@ import logging
|
|||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_TEMP,
|
||||
ATTR_EFFECT,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_TRANSITION,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
SUPPORT_COLOR,
|
||||
SUPPORT_COLOR_TEMP,
|
||||
SUPPORT_EFFECT,
|
||||
Light,
|
||||
)
|
||||
|
@ -60,6 +62,8 @@ class HMLight(HMDevice, Light):
|
|||
features |= SUPPORT_COLOR
|
||||
if "PROGRAM" in self._hmdevice.WRITENODE:
|
||||
features |= SUPPORT_EFFECT
|
||||
if hasattr(self._hmdevice, "get_color_temp"):
|
||||
features |= SUPPORT_COLOR_TEMP
|
||||
return features
|
||||
|
||||
@property
|
||||
|
@ -70,6 +74,14 @@ class HMLight(HMDevice, Light):
|
|||
hue, sat = self._hmdevice.get_hs_color(self._channel)
|
||||
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
|
||||
def effect_list(self):
|
||||
"""Return the list of supported effects."""
|
||||
|
@ -92,7 +104,11 @@ class HMLight(HMDevice, Light):
|
|||
if ATTR_BRIGHTNESS in kwargs and self._state == "LEVEL":
|
||||
percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255
|
||||
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)
|
||||
|
||||
if ATTR_HS_COLOR in kwargs:
|
||||
|
@ -101,6 +117,11 @@ class HMLight(HMDevice, Light):
|
|||
saturation=kwargs[ATTR_HS_COLOR][1] / 100.0,
|
||||
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:
|
||||
self._hmdevice.set_effect(kwargs[ATTR_EFFECT])
|
||||
|
||||
|
|
Loading…
Reference in New Issue