mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
fix knx light turn_on with ct (#31184)
process both brightness and color_temperature in a turn_on call.
This commit is contained in:
parent
c2f1d6aa19
commit
9ff9614d0b
@ -269,8 +269,16 @@ class KNXLight(Light):
|
|||||||
update_white_value = ATTR_WHITE_VALUE in kwargs
|
update_white_value = ATTR_WHITE_VALUE in kwargs
|
||||||
update_color_temp = ATTR_COLOR_TEMP in kwargs
|
update_color_temp = ATTR_COLOR_TEMP in kwargs
|
||||||
|
|
||||||
# always only go one path for turning on (avoid conflicting changes
|
# avoid conflicting changes and weird effects
|
||||||
# and weird effects)
|
if not (
|
||||||
|
self.is_on
|
||||||
|
or update_brightness
|
||||||
|
or update_color
|
||||||
|
or update_white_value
|
||||||
|
or update_color_temp
|
||||||
|
):
|
||||||
|
await self.device.set_on()
|
||||||
|
|
||||||
if self.device.supports_brightness and (update_brightness and not update_color):
|
if self.device.supports_brightness and (update_brightness and not update_color):
|
||||||
# if we don't need to update the color, try updating brightness
|
# if we don't need to update the color, try updating brightness
|
||||||
# directly if supported; don't do it if color also has to be
|
# directly if supported; don't do it if color also has to be
|
||||||
@ -279,7 +287,7 @@ class KNXLight(Light):
|
|||||||
elif (self.device.supports_rgbw or self.device.supports_color) and (
|
elif (self.device.supports_rgbw or self.device.supports_color) and (
|
||||||
update_brightness or update_color or update_white_value
|
update_brightness or update_color or update_white_value
|
||||||
):
|
):
|
||||||
# change RGB color, white value )if supported), and brightness
|
# change RGB color, white value (if supported), and brightness
|
||||||
# if brightness or hs_color was not yet set use the default value
|
# if brightness or hs_color was not yet set use the default value
|
||||||
# to calculate RGB from as a fallback
|
# to calculate RGB from as a fallback
|
||||||
if brightness is None:
|
if brightness is None:
|
||||||
@ -290,29 +298,20 @@ class KNXLight(Light):
|
|||||||
white_value = DEFAULT_WHITE_VALUE
|
white_value = DEFAULT_WHITE_VALUE
|
||||||
rgb = color_util.color_hsv_to_RGB(*hs_color, brightness * 100 / 255)
|
rgb = color_util.color_hsv_to_RGB(*hs_color, brightness * 100 / 255)
|
||||||
await self.device.set_color(rgb, white_value)
|
await self.device.set_color(rgb, white_value)
|
||||||
elif self.device.supports_color_temperature and update_color_temp:
|
|
||||||
# change color temperature without ON telegram
|
if update_color_temp:
|
||||||
kelvin = int(color_util.color_temperature_mired_to_kelvin(mireds))
|
kelvin = int(color_util.color_temperature_mired_to_kelvin(mireds))
|
||||||
if kelvin > self._max_kelvin:
|
kelvin = min(self._max_kelvin, max(self._min_kelvin, kelvin))
|
||||||
kelvin = self._max_kelvin
|
|
||||||
elif kelvin < self._min_kelvin:
|
if self.device.supports_color_temperature:
|
||||||
kelvin = self._min_kelvin
|
await self.device.set_color_temperature(kelvin)
|
||||||
await self.device.set_color_temperature(kelvin)
|
elif self.device.supports_tunable_white:
|
||||||
elif self.device.supports_tunable_white and update_color_temp:
|
relative_ct = int(
|
||||||
# calculate relative_ct from Kelvin to fit typical KNX devices
|
255
|
||||||
kelvin = min(
|
* (kelvin - self._min_kelvin)
|
||||||
self._max_kelvin,
|
/ (self._max_kelvin - self._min_kelvin)
|
||||||
int(color_util.color_temperature_mired_to_kelvin(mireds)),
|
)
|
||||||
)
|
await self.device.set_tunable_white(relative_ct)
|
||||||
relative_ct = int(
|
|
||||||
255
|
|
||||||
* (kelvin - self._min_kelvin)
|
|
||||||
/ (self._max_kelvin - self._min_kelvin)
|
|
||||||
)
|
|
||||||
await self.device.set_tunable_white(relative_ct)
|
|
||||||
else:
|
|
||||||
# no color/brightness change requested, so just turn it on
|
|
||||||
await self.device.set_on()
|
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs):
|
||||||
"""Turn the light off."""
|
"""Turn the light off."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user