def defaultDispatcher_init(): config = ConfigurationServer() config.port = 8008 config.nombre = "admin" config.dispatcher = SoapDispatcher( 'my_dispatcher', location = "http://localhost:8008", action = 'http://localhost:8008', #SOAPAction namespace = "http://example.com/sample.wsdl", prefix = "ns0", trace = True, ns = True ) config.dispatcher.register_function('adminRequest',defaultDispatcher_logic, returns = {'msg' : str}, args={'operation' : str } ) # config.dispatcher.register_function('Adder',adder, # returns = {'AddResult' : int}, # args = {'a':int, 'b':int} # ) return config
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)
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)
def __init__(self): self.http = httplib2.Http() self.config = ConfigurationServer.get('AutoOn') if self.config == None: self.config = { 'lat': 0, 'long': 0, 'city': 'Enter a city here...', 'offset': 0, 'autoOnGroup': 'All Lights', 'groupBri': 255, } else: if not 'autoOnGroup' in self.config.keys(): self.config['autoOnGroup'] = 'All Lights' if not 'groupBri' in self.config.keys(): self.config['groupBri'] = 255 minute = random.randint(0,59) start_date = datetime.datetime.combine(datetime.datetime.today(), datetime.time(hour=12, minute=minute, second=0)) #added randomness to not break earthtools :) if start_date < datetime.datetime.now(): # get the sunset for today, the get_sunset function will take care of the rest self.get_sunset() start_date += datetime.timedelta(days=1) Scheduler.add_interval_job(self.get_sunset, days=1, start_date=start_date)
def __init__(self, bridgeIP): self.bridgeIP = bridgeIP self.http = httplib2.Http() self.base_url = "http://{}".format(bridgeIP) self.api_key = ConfigurationServer.get('HueConnection')