mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-23 07:54:25 +01:00
limit lower bound of color brightness scale
This commit is contained in:
@@ -10,6 +10,7 @@ def scale(val, src, dst):
|
||||
def hsv2rgb(h, s, v):
|
||||
hsv = colorsys.hsv_to_rgb(h,s,v)
|
||||
return tuple(round(i * 255) for i in hsv)
|
||||
|
||||
def pos_to_color(x, y):
|
||||
r = 160/2
|
||||
x = round((x - r) / r * 100) / 100
|
||||
@@ -26,10 +27,13 @@ def pos_to_color(x, y):
|
||||
return rgb
|
||||
|
||||
def rgb_brightness(rgb_color, brightness):
|
||||
# brightness values are in range 0-255
|
||||
# to make sure that the color is not completly lost we need to rescale this to 70-255
|
||||
brightness = int(scale(entity.attributes.brightness,(0,255),(70,255)))
|
||||
red = rgb_color[0]/255*brightness
|
||||
green = rgb_color[1]/255*brightness
|
||||
blue = rgb_color[2]/255*brightness
|
||||
return [red, green, blue]
|
||||
return [int(red), int(green), int(blue)]
|
||||
|
||||
def rgb_dec565(rgb_color):
|
||||
red = rgb_color[0]
|
||||
|
||||
@@ -34,7 +34,7 @@ class LuiPagesGen(object):
|
||||
color = rgb_brightness(color, attr.brightness)
|
||||
icon_color = rgb_dec565(color)
|
||||
elif "brightness" in attr:
|
||||
color = rgb_brightness([253, 216, 53], max(70, attr.brightness))
|
||||
color = rgb_brightness([253, 216, 53], attr.brightness)
|
||||
icon_color = rgb_dec565(color)
|
||||
return icon_color
|
||||
|
||||
@@ -280,9 +280,9 @@ class LuiPagesGen(object):
|
||||
brightness = "disable"
|
||||
color_temp = "disable"
|
||||
color = "disable"
|
||||
# scale 0-255 brightness from ha to 0-100
|
||||
if entity.state == "on":
|
||||
if "brightness" in entity.attributes:
|
||||
# scale 0-255 brightness from ha to 0-100
|
||||
brightness = int(scale(entity.attributes.brightness,(0,255),(0,100)))
|
||||
else:
|
||||
brightness = "disable"
|
||||
|
||||
Reference in New Issue
Block a user