Esempio n. 1
0
File: light.py Progetto: raudiez/tfg
 def get(self, resource={'which':'all'}):
   """
   @summary: Get all lights, get new lights, or get a specific light as
             determined by the resource object.
   """
   rest_obj = RestObject()
   services = {
     'all':{'service':'lights'},
     'new':{'service':'lights/new'}
   }
   if (isinstance(resource['which'], int)):
     resource['id'] = resource['which']
     resource['which'] = 'one'
   if (resource['which'] == 'one'):
     services['one'] = {'service':'lights/{id}'.format(id=resource['id'])}
   service = services[resource['which']]['service']
   path = 'api/{username}/{service}'.format(username=self.user['name'], service=service)
   url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'], path=path)
   response = rest_obj.get(url)
   if service == 'lights':
     lights = []
     for (k, v) in response.items():
       v['id'] = int(k)
       lights.append(v)
     response = lights
   return dict(resource=response)
Esempio n. 2
0
 def get(self, resource={'which': 'all'}):
     """
 @summary: Get all lights, get new lights, or get a specific light as
           determined by the resource object.
 """
     rest_obj = RestObject()
     services = {
         'all': {
             'service': 'lights'
         },
         'new': {
             'service': 'lights/new'
         }
     }
     if (isinstance(resource['which'], int)):
         resource['id'] = resource['which']
         resource['which'] = 'one'
     if (resource['which'] == 'one'):
         services['one'] = {
             'service': 'lights/{id}'.format(id=resource['id'])
         }
     service = services[resource['which']]['service']
     path = 'api/{username}/{service}'.format(username=self.user['name'],
                                              service=service)
     url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'],
                                              path=path)
     response = rest_obj.get(url)
     if service == 'lights':
         lights = []
         for (k, v) in response.items():
             v['id'] = int(k)
             lights.append(v)
         response = lights
     return dict(resource=response)
Esempio n. 3
0
File: light.py Progetto: raudiez/tfg
 def getNumLights(self):
   """
   @summary: Get num of Lights connected.
   @return: Num of lights.
   """
   rest_obj = RestObject()
   path = 'api/{username}/lights'.format(username=self.user['name'])
   url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'], path=path)
   response = rest_obj.get(url)
   lights = []
   for (k, v) in response.items():
     v['id'] = int(k)
     lights.append(v)
   return len(lights)
Esempio n. 4
0
 def getNumLights(self):
     """
 @summary: Get num of Lights connected.
 @return: Num of lights.
 """
     rest_obj = RestObject()
     path = 'api/{username}/lights'.format(username=self.user['name'])
     url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'],
                                              path=path)
     response = rest_obj.get(url)
     lights = []
     for (k, v) in response.items():
         v['id'] = int(k)
         lights.append(v)
     return len(lights)
Esempio n. 5
0
 def isConnected(self):
   """
   @summary: See if Hue is connected.
   @return: Boolean which determines if there is connection stablished, and string with connection message.
   """
   rest_obj = RestObject()
   path = 'api/{username}'.format(username=self.user['name'])
   url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'], path=path)
   response = rest_obj.get(url)
   response = dict(resource=response)
   if 'lights' in response['resource']:
     return True
   elif 'error' in response['resource'][0]:
     error = response['resource'][0]['error']
     if error['type'] == 1:
       return False
Esempio n. 6
0
 def isConnected(self):
     """
 @summary: See if Hue is connected.
 @return: Boolean which determines if there is connection stablished, and string with connection message.
 """
     rest_obj = RestObject()
     path = 'api/{username}'.format(username=self.user['name'])
     url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'],
                                              path=path)
     response = rest_obj.get(url)
     response = dict(resource=response)
     if 'lights' in response['resource']:
         return True
     elif 'error' in response['resource'][0]:
         error = response['resource'][0]['error']
         if error['type'] == 1:
             return False