Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
"""
main
"""
hue_bridge = qhue.Bridge(os.environ.get('HUE_BRIDGE'),
os.environ.get('HUE_USERNAME'))
if not hue_bridge:
print("Oops")
sys.exit(1)
sensors = hue_bridge.sensors
for _, sensor in sensors().items():
if sensor.get('type') == 'ZLLSwitch':
__memory__[sensor['uniqueid']] = sensor['state']['lastupdated']
print("Started")
sleep_time = os.environ.get('SLEEP_TIME', 0.3)
while True:
try:
for _, sensor in sensors().items():
if sensor.get('type') == 'ZLLSwitch':
check_change((sensor))
time.sleep(sleep_time)
"flipendo": {"hue": 37445, "bri": 150, "sat": 140},
"expelliarmus": {"hue": 1547, "bri": 200, "sat": 200},
"incendio": {"hue": 7063, "bri": 200, "sat": 250},
"lumos": {"hue": 0, "bri": 204, "sat": 0},
"locomotor": {"hue": 12324, "bri": 100, "sat": 140},
"engorgio": {"hue": 32275, "bri": 125, "sat": 120},
"aguamenti": {"hue": 32275, "bri": 180, "sat": 200},
"avis": {"hue": 37445, "bri": 150, "sat": 130},
"reducto": {"hue": 37445, "bri": 180, "sat": 200}
}
self.current = self.color_values[None]
# Bridge api values
self.bridge_ip = "192.168.1.22"
self.username = "dBHN8d6Qkw6EJMqzEI2oI0zXJGiOdvyE2lRzFha8"
# Bridge object and lights
self.bridge = Bridge(self.bridge_ip, self.username)
self.light_ids = ["1"]
self.light_states = {}
for id in self.light_ids:
# Backup the state of all the lights
light = self.bridge.lights[id]
state = {"on": True, **self.color_values[None]}
s = light()['state']
for key in state:
state[key] = s.get(key)
self.light_states[id] = state
# Set the default state for the bulb
light.state(on=True, **self.color_values[None])
import sys
from qhue import Bridge
from rgb_cie import Converter
import os
converter = Converter()
f = open("hue_id.txt", "r")
hue_id = f.readlines()[-1].rstrip()
f.close()
b = Bridge(hue_id, "elbLovRPUcHaqss904iEJMH9LZrRwsvFeOKSfvOP")
strip_bri = b.lights[1]()['state']['bri']
bloom_1_bri = b.lights[2]()['state']['bri']
bloom_2_bri = b.lights[3]()['state']['bri']
strip_2_bri = b.lights[4]()['state']['bri']
strip_xy = b.lights[1]()['state']['xy']
bloom_1_xy = b.lights[2]()['state']['xy']
bloom_2_xy = b.lights[3]()['state']['xy']
strip_2_xy = b.lights[4]()['state']['xy']
strip_hex = converter.CIE1931ToHex(strip_xy[0], strip_xy[1], bri=(strip_bri/254.0))
bloom_1_hex = converter.CIE1931ToHex(bloom_1_xy[0], bloom_1_xy[1], bri=(bloom_1_bri/254.0))
bloom_2_hex = converter.CIE1931ToHex(bloom_2_xy[0], bloom_2_xy[1], bri=(bloom_2_bri/254.0))
strip_2_hex = converter.CIE1931ToHex(strip_2_xy[0], strip_2_xy[1], bri=(strip_2_bri/254.0))
def __init__(
self,
portfolio_balance,
bridge_ip=os.getenv('HUE_BRIDGE_IP'),
down_color='red',
up_color='green',
light_ids=[],
num_colors_in_range=100,
performance_thresh=0.02):
self.bridge = Bridge(bridge_ip, username=os.getenv('HUE_BRIDGE_USER'))
self.light_ids = light_ids
self._color_map = {
'red': 0, 'yellow': 12750, 'green': 25500,
'blue': 46920, 'violet': 56100, 'max': 65280
}
self.down_color = self._color_map[down_color]
self.up_color = self._color_map[up_color]
self.num_colors_in_range = num_colors_in_range
# (color is scaled between -n% and +n%)
self.performance_thresh = performance_thresh
self.start_balance = portfolio_balance
import sys
import os
from qhue import Bridge
from rgb_cie import Converter
f = open("hue_id.txt", "r")
hue_id = f.readlines()[-1].rstrip()
f.close()
b = Bridge(hue_id, "elbLovRPUcHaqss904iEJMH9LZrRwsvFeOKSfvOP")
lights = b.lights
converter = Converter()
b.lights(1, 'state', on=True, xy=converter.hexToCIE1931(sys.argv[-4]))
b.lights(2, 'state', on=True, xy=converter.hexToCIE1931(sys.argv[-3]))
b.lights(3, 'state', on=True, xy=converter.hexToCIE1931(sys.argv[-2]))
b.lights(4, 'state', on=True, xy=converter.hexToCIE1931(sys.argv[-1]))
import sys
from qhue import Bridge
import os
f = open("hue_id.txt", "r")
hue_id = f.readlines()[-1].rstrip()
f.close()
b = Bridge(hue_id, "elbLovRPUcHaqss904iEJMH9LZrRwsvFeOKSfvOP")
lights = b.lights
brightness = int(sys.argv[-1])
print(int(sys.argv[-1]))
if len(sys.argv) < 3:
if brightness < 1:
b.lights(1, 'state', on=False)
b.lights(2, 'state', on=False)
b.lights(3, 'state', on=False)
b.lights(4, 'state', on=False)
else:
if brightness > 255:
brightness = 255
def main_(arguments):
username = arguments.username or get_saved_username()
if not username:
username = prompt_create_username(arguments.bridge_address)
if not username:
return FAILURE_EXIT_CODE
save_username(username)
bridge = qhue.Bridge(arguments.bridge_address, username)
initial_states = {}
for light in arguments.lights:
state = bridge.lights[light]()['state']
initial_states[light] = state
if arguments.enable and not state['on']:
bridge.lights[light].state(on=True)
if arguments.restore_state:
def restore_state():
for light, state in initial_states.items():
change_light_state(bridge, light, state)
atexit.register(restore_state)
previous_color = None
def __init__(self, host=None, user=None):
self.enabled = (not host is None)
if not (host and user):
self.hue_bridge = None
return None
self.check_import()
import qhue
try:
self.hue_bridge = qhue.Bridge(host, user)
except:
IkaUtils.dprint('%s: Exception.' % self)
IkaUtils.dprint(traceback.format_exc())