mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2026-02-09 23:06:34 +01:00
set current rgb_color
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import colorsys
|
import colorsys
|
||||||
|
import math
|
||||||
|
|
||||||
def hsv2rgb(self, h, s, v):
|
def hsv2rgb(h, s, v):
|
||||||
hsv = colorsys.hsv_to_rgb(h,s,v)
|
hsv = colorsys.hsv_to_rgb(h,s,v)
|
||||||
return tuple(round(i * 255) for i in hsv)
|
return tuple(round(i * 255) for i in hsv)
|
||||||
def pos_to_color(self, x, y):
|
def pos_to_color(x, y):
|
||||||
r = 160/2
|
r = 160/2
|
||||||
x = round((x - r) / r * 100) / 100
|
x = round((x - r) / r * 100) / 100
|
||||||
y = round((r - y) / r * 100) / 100
|
y = round((r - y) / r * 100) / 100
|
||||||
@@ -15,10 +16,13 @@ def pos_to_color(self, x, y):
|
|||||||
else:
|
else:
|
||||||
sat = r
|
sat = r
|
||||||
hsv = (math.degrees(math.atan2(y, x))%360/360, sat, 1)
|
hsv = (math.degrees(math.atan2(y, x))%360/360, sat, 1)
|
||||||
rgb = self.hsv2rgb(hsv[0],hsv[1],hsv[2])
|
rgb = hsv2rgb(hsv[0],hsv[1],hsv[2])
|
||||||
return rgb
|
return rgb
|
||||||
|
|
||||||
def rgb_dec565(red, green, blue):
|
def rgb_dec565(rgb_color):
|
||||||
|
red = rgb_color[0]
|
||||||
|
green = rgb_color[1]
|
||||||
|
blue = rgb_color[2]
|
||||||
# take in the red, green and blue values (0-255) as 8 bit values and then combine
|
# take in the red, green and blue values (0-255) as 8 bit values and then combine
|
||||||
# and shift them to make them a 16 bit dec value in 565 format.
|
# and shift them to make them a 16 bit dec value in 565 format.
|
||||||
print ((int(red / 255 * 31) << 11) | (int(green / 255 * 63) << 5) | (int(blue / 255 * 31)))
|
return ((int(red / 255 * 31) << 11) | (int(green / 255 * 63) << 5) | (int(blue / 255 * 31)))
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
import hassapi as hass
|
import hassapi as hass
|
||||||
import math
|
from color import pos_to_color, rgb_dec565
|
||||||
from color import hsv2rgb,pos_to_color
|
|
||||||
|
|
||||||
# check Babel
|
# check Babel
|
||||||
import importlib
|
import importlib
|
||||||
@@ -247,7 +246,7 @@ class NsPanelLovelaceUI:
|
|||||||
if(btype == "colorWheel"):
|
if(btype == "colorWheel"):
|
||||||
self.api.log(optVal)
|
self.api.log(optVal)
|
||||||
optVal = optVal.split('|')
|
optVal = optVal.split('|')
|
||||||
color = self.pos_to_color(int(optVal[0]), int(optVal[1]))
|
color = pos_to_color(int(optVal[0]), int(optVal[1]))
|
||||||
self.api.log(color)
|
self.api.log(color)
|
||||||
self.api.get_entity(entity_id).call_service("turn_on", rgb_color=color)
|
self.api.get_entity(entity_id).call_service("turn_on", rgb_color=color)
|
||||||
|
|
||||||
@@ -367,7 +366,8 @@ class NsPanelLovelaceUI:
|
|||||||
switch_val = 1 if entity.state == "on" else 0
|
switch_val = 1 if entity.state == "on" else 0
|
||||||
icon_color = 17299
|
icon_color = 17299
|
||||||
|
|
||||||
|
if "rgb_color" in entity.attributes:
|
||||||
|
icon_color = rgb_dec565(entity.attributes.rgb_color)
|
||||||
|
|
||||||
return f",{item_type},{item},1,{icon_color},{name},{switch_val}"
|
return f",{item_type},{item},1,{icon_color},{name},{switch_val}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user