Example #1
0
 def authenticate(self, applicationName):
     if self.api_key == None:
         cmd = {"username": applicationName, "devicetype": applicationName}
         data = simplejson.dumps(cmd)
         resp, content = self.http.request("{}/api".format(self.base_url), method="POST",body=data)
         if resp.status != 200:
             raise ConnectionException("Returncode {} from bridge!".format(resp.status))
         cherrypy.log("{}: {}".format(resp.status, content))
         response = simplejson.loads(content)
         if 'error' in response[0].keys():
             raise ConnectionException(response[0]['error']['description'])
         self.api_key = response[0]['success']['username']
         ConfigurationServer.save('HueConnection', self.api_key)
Example #2
0
 def save(self, **jsonData):
     loc = jsonData['location']
     offset = int(jsonData['offset'])
     group = jsonData['autoOnGroup']
     bri = int(jsonData['groupBri'])
     geocode_url = "https://maps.googleapis.com/maps/api/geocode/json?address={}&sensor=false".format(urllib2.quote(loc))
     req = urllib2.urlopen(geocode_url)
     resp = simplejson.loads(req.read())
     self.config['lat'] = resp['results'][0]['geometry']['location']['lat']
     self.config['long'] = resp['results'][0]['geometry']['location']['lng']
     self.config['city'] = loc
     self.config['offset'] = offset
     self.config['autoOnGroup'] = group
     self.config['groupBri'] = bri
     ConfigurationServer.save('AutoOn', self.config)