Skip to content

Commit

Permalink
Refactor bruteforce.py
Browse files Browse the repository at this point in the history
  • Loading branch information
palfrey committed Jul 20, 2013
1 parent 416f9cf commit 4c03406
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 50 deletions.
51 changes: 1 addition & 50 deletions bruteforce.py
@@ -1,51 +1,7 @@
import requests
import json
from colorpy import colormodels
from time import sleep, time
import random
import pickle

ip = "169.254.87.149"
key = "7278ce1e7d0c44811ab4f854b75a234e"
base = "http://" + ip + "/api/" + key

data = requests.get(base).json
print data

lights = sorted(data["lights"].keys())
print lights

def set_state(light, state):
path = base + "/lights/%s/state" % light
print path
data = json.dumps(state)
print data
resp = requests.request("PUT", path, data=data)
print resp.json

def rgb(light, red, green=None, blue=None, transitiontime=1):
if isinstance(red, basestring):
# assume a hex string is passed
rstring = red
red = int(rstring[1:3], 16)
green = int(rstring[3:5], 16)
blue = int(rstring[5:], 16)

print red, green, blue

# We need to convert the RGB value to Yxy.
redScale = float(red) / 255.0
greenScale = float(green) / 255.0
blueScale = float(blue) / 255.0
colormodels.init(
phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
phosphor_green=colormodels.xyz_color(0.4091, 0.518),
phosphor_blue=colormodels.xyz_color(0.167, 0.04))
xyz = colormodels.irgb_color(red, green, blue)
xyz = colormodels.xyz_from_rgb(xyz)
xyz = colormodels.xyz_normalize(xyz)

return set_state(light, {"xy": [xyz[0], xyz[1]], "transitiontime": transitiontime, "on": True})
from hue import *

random.seed()
tf = "times.pickle"
Expand All @@ -55,11 +11,6 @@ def rgb(light, red, green=None, blue=None, transitiontime=1):
except:
times = {}

def frange(start, stop, step):
while start < stop:
yield start
start += step

for period in frange(0.0, 1.0, 0.05):
if period not in times:
times[period] = []
Expand Down
45 changes: 45 additions & 0 deletions hue.py
@@ -0,0 +1,45 @@
import requests
import json
from colorpy import colormodels

ip = "169.254.87.149"
key = "7278ce1e7d0c44811ab4f854b75a234e"
base = "http://" + ip + "/api/" + key

def lights():
data = requests.get(base).json
lights = sorted(data["lights"].keys())
return lights

def frange(start, stop, step):
while start < stop:
yield start
start += step

def set_state(light, state):
path = base + "/lights/%s/state" % light
data = json.dumps(state)
resp = requests.request("PUT", path, data=data)
print resp.json

def rgb(light, red, green=None, blue=None, transitiontime=1):
if isinstance(red, basestring):
# assume a hex string is passed
rstring = red
red = int(rstring[1:3], 16)
green = int(rstring[3:5], 16)
blue = int(rstring[5:], 16)

# We need to convert the RGB value to Yxy.
redScale = float(red) / 255.0
greenScale = float(green) / 255.0
blueScale = float(blue) / 255.0
colormodels.init(
phosphor_red=colormodels.xyz_color(0.64843, 0.33086),
phosphor_green=colormodels.xyz_color(0.4091, 0.518),
phosphor_blue=colormodels.xyz_color(0.167, 0.04))
xyz = colormodels.irgb_color(red, green, blue)
xyz = colormodels.xyz_from_rgb(xyz)
xyz = colormodels.xyz_normalize(xyz)

return set_state(light, {"xy": [xyz[0], xyz[1]], "transitiontime": transitiontime, "on": True})

0 comments on commit 4c03406

Please sign in to comment.