Skip to content

Commit

Permalink
Can now send all commands using the set_state() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathanaël Lécaudé authored and Nathanaël Lécaudé committed Nov 4, 2012
1 parent f487d66 commit c1bee79
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,21 @@ def connect(self):
print 'Error opening config file, will attempt bridge registration'
self.register_app()

def get_bridge_information(self):
u = urllib2.urlopen(self.bridge_api_url + self.username)

# With no arguments, prints the whole bridge information, with a lamp_id, prints the lamp information.
def get_info(self, lamp_id = None):
if lamp_id != None:
u = urllib2.urlopen(self.bridge_api_url + self.username + '/lights/' + str(lamp_id))
else:
u = urllib2.urlopen(self.bridge_api_url + self.username)
for line in u.readlines():
print json.dumps(json.loads(line), indent=4)

def set_brightness(self, lamp_id, brightness):
data = {'bri' : brightness}
# parameters: 'on' : True|False , 'bri' : 0-254, 'sat' : 0-254, 'ct': 154-500
def set_state(self, lamp_id, parameter, value):
data = {parameter : value}
connection = httplib.HTTPConnection(self.bridge_ip + ':80')
connection.request('PUT', '/api/' + self.username + '/lights/'+ str(lamp_id) + '/state', json.dumps(data))
result = connection.getresponse()
print result.read()

0 comments on commit c1bee79

Please sign in to comment.