Clamp color temperature to supported range in ESPHome light (#54595)

ESPHome devices initially report a color temperature of 0 or 1 until it
has been changed by the user. This broke the conversion from RGBWW to
an RGB color.

Fixes #54293.
pull/54622/head
Oxan van Leeuwen 2021-08-14 08:27:47 +02:00 committed by GitHub
parent c10497d499
commit 2c181181e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -230,7 +230,7 @@ class EsphomeLight(EsphomeEntity[LightInfo, LightState], LightEntity):
# Try to reverse white + color temp to cwww
min_ct = self._static_info.min_mireds
max_ct = self._static_info.max_mireds
color_temp = self._state.color_temperature
color_temp = min(max(self._state.color_temperature, min_ct), max_ct)
white = self._state.white
ww_frac = (color_temp - min_ct) / (max_ct - min_ct)