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
This commit is contained in:
Matthias Alphart 2019-09-07 01:38:09 +02:00 committed by Martin Hjelmare
parent 48dea59517
commit a5ccb03e2e

View File

@ -305,7 +305,10 @@ class KNXLight(Light):
await self.device.set_color_temperature(kelvin) await self.device.set_color_temperature(kelvin)
elif self.device.supports_tunable_white and update_color_temp: elif self.device.supports_tunable_white and update_color_temp:
# calculate relative_ct from Kelvin to fit typical KNX devices # 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( relative_ct = int(
255 255
* (kelvin - self._min_kelvin) * (kelvin - self._min_kelvin)