Fix MQTT rgb light brightness scaling (#89264)
* Normalize received RGB colors to 100% brightness * Assert on rgb_color attribute * Use max for RGB to get brightness * Avoid division and add clamp * remove clamp Co-authored-by: Erik Montnemery <erik@montnemery.com> --------- Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
e5ce8e920d
commit
1a4b14c217
2 changed files with 28 additions and 5 deletions
|
@ -495,8 +495,12 @@ class MqttLight(MqttEntity, LightEntity, RestoreEntity):
|
|||
self._attr_color_mode = color_mode
|
||||
if self._topic[CONF_BRIGHTNESS_STATE_TOPIC] is None:
|
||||
rgb = convert_color(*color)
|
||||
percent_bright = float(color_util.color_RGB_to_hsv(*rgb)[2]) / 100.0
|
||||
self._attr_brightness = min(round(percent_bright * 255), 255)
|
||||
brightness = max(rgb)
|
||||
self._attr_brightness = brightness
|
||||
# Normalize the color to 100% brightness
|
||||
color = tuple(
|
||||
min(round(channel / brightness * 255), 255) for channel in color
|
||||
)
|
||||
return color
|
||||
|
||||
@callback
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue