From a5ccb03e2eb8dad11ea2366919bff917530ddb4a Mon Sep 17 00:00:00 2001 From: Matthias Alphart Date: Sat, 7 Sep 2019 01:38:09 +0200 Subject: [PATCH] Fix KNX light tunable white rounding error (#26364) * KNX light - tunable white rounding error mitigate rounding errors in kelvin - mired conversion for lights with relative color temperature fixes https://github.com/home-assistant/home-assistant/issues/26357 * typo _min_kelvin <> _max_kelvin * black --- homeassistant/components/knx/light.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/knx/light.py b/homeassistant/components/knx/light.py index c04feed2337..71a82c6df2a 100644 --- a/homeassistant/components/knx/light.py +++ b/homeassistant/components/knx/light.py @@ -305,7 +305,10 @@ class KNXLight(Light): await self.device.set_color_temperature(kelvin) elif self.device.supports_tunable_white and update_color_temp: # calculate relative_ct from Kelvin to fit typical KNX devices - kelvin = int(color_util.color_temperature_mired_to_kelvin(mireds)) + kelvin = min( + self._max_kelvin, + int(color_util.color_temperature_mired_to_kelvin(mireds)), + ) relative_ct = int( 255 * (kelvin - self._min_kelvin)