From 408652ba0c327f50fdb5d2999f07010a6dd6f519 Mon Sep 17 00:00:00 2001 From: Gerd Zanker Date: Wed, 3 Apr 2024 20:03:27 +0200 Subject: [PATCH] avoids a float division by zero for tasmota lights, when light is dimmed off (#1013) --- BridgeEmulator/functions/colors.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/BridgeEmulator/functions/colors.py b/BridgeEmulator/functions/colors.py index 258e53ead..223259c3d 100755 --- a/BridgeEmulator/functions/colors.py +++ b/BridgeEmulator/functions/colors.py @@ -21,8 +21,14 @@ def convert_rgb_xy(red, green, blue): Z = red * 0.000088 + green * 0.072310 + blue * 0.986039 #Calculate the xy values from the XYZ values - x = X / (X + Y + Z) - y = Y / (X + Y + Z) + div = X + Y + Z + if div < 0.000001: + # set values to zero in case of div by zero + x = 0 + y = 0 + else: + x = X / div + y = Y / div return [x, y] def convert_xy(x, y, bri): #needed for milight hub that don't work with xy values