99 lines
3.2 KiB
Python
99 lines
3.2 KiB
Python
from time import sleep
|
|
import phue
|
|
from phue import Bridge
|
|
|
|
import random
|
|
|
|
import credentials
|
|
import config
|
|
|
|
class Lights_Modules():
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def main(self):
|
|
print("Starting up Lights_Modules....")
|
|
b = Bridge('192.168.191.146')
|
|
b.connect
|
|
|
|
b.get_api()
|
|
|
|
light_list = b.lights
|
|
group_list:list = []
|
|
groups = b.get_group()
|
|
groupCount = 0
|
|
|
|
print("\n -Listing Lights...")
|
|
for l in light_list:
|
|
print(l.name)
|
|
print("\n -Counting Groups...")
|
|
for g in groups:
|
|
print(g)
|
|
groupCount = int(g)
|
|
|
|
|
|
for gc in range(groupCount):
|
|
try:
|
|
print("group n:" + str(gc))
|
|
group = b.get_group(gc ,'name')
|
|
print(group)
|
|
#group_list.append(group)
|
|
print(" --done adding")
|
|
except:
|
|
print(" --adding failed")
|
|
|
|
#b.set_group(18, "bri", 254) #This is max Brightness
|
|
#b.set_group(18, "on", True) #This is will turn ON
|
|
xy_result = self.rgb_to_xy(0,0,1) #This will take an rgb value and make it xy
|
|
b.set_group(16, "xy", xy_result) #This will make the lights in the group turn blue
|
|
|
|
# The Following will make a rave
|
|
for rave in range(2000):
|
|
rgb_r = random.random()
|
|
rgb_g = random.random()
|
|
rgb_b = random.random()
|
|
xy_result = self.rgb_to_xy(rgb_r, rgb_g, rgb_b) #This will take an rgb value and make it xy
|
|
b.set_group(16, "xy", xy_result)
|
|
sleep(0.5)
|
|
|
|
print("\n finished doing the things")
|
|
|
|
|
|
|
|
def rgb_to_xy(self, red, green, blue):
|
|
""" conversion of RGB colors to CIE1931 XY colors
|
|
Formulas implemented from: https://gist.github.com/popcorn245/30afa0f98eea1c2fd34d
|
|
Args:
|
|
red (float): a number between 0.0 and 1.0 representing red in the RGB space
|
|
green (float): a number between 0.0 and 1.0 representing green in the RGB space
|
|
blue (float): a number between 0.0 and 1.0 representing blue in the RGB space
|
|
Returns:
|
|
xy (list): x and y
|
|
"""
|
|
# gamma correction
|
|
red = pow((red + 0.055) / (1.0 + 0.055), 2.4) if red > 0.04045 else (red / 12.92)
|
|
green = pow((green + 0.055) / (1.0 + 0.055), 2.4) if green > 0.04045 else (green / 12.92)
|
|
blue = pow((blue + 0.055) / (1.0 + 0.055), 2.4) if blue > 0.04045 else (blue / 12.92)
|
|
|
|
# convert rgb to xyz
|
|
x = red * 0.649926 + green * 0.103455 + blue * 0.197109
|
|
y = red * 0.234327 + green * 0.743075 + blue * 0.022598
|
|
z = green * 0.053077 + blue * 1.035763
|
|
|
|
# convert xyz to xy
|
|
x = x / (x + y + z)
|
|
y = y / (x + y + z)
|
|
|
|
# TODO check color gamut if known
|
|
return [x, y]
|
|
|
|
|
|
if __name__ == "__main__":
|
|
testModule = Lights_Modules()
|
|
|
|
credentials_manager = credentials.Credentials_Module()
|
|
credentials_manager.load_credentials()
|
|
#testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname)
|
|
#testModule.discordCredential = credentials_manager.find_Discord_Credential(config.credentialsNickname)
|
|
|
|
testModule.main() |