示例#1
0
    def get(self, resource, debug=False):
        """
        @summary: Get all lights, get new lights, or get a specific light as\
                  determined by the resource object.

        @TODO: Fix resource variable scope issue that manifests when making\
               multiple light.get(resource) calls.
        """

        request = Request()
        services = {
            'all': {
                'service': 'lights'
            },
            'new': {
                'service': 'lights/new'
            }
        }

        if (isinstance(resource['which'], int)):
            resource['id'] = resource['which']
            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)

        status, content = request.get(url, resource)
        if service == 'lights':
            lights = []
            for (k, v) in content.items():
                v['id'] = int(k)
                lights.append(v)
            if resource.has_key('verbose') and resource['verbose']:
                _lights = []
                for light in lights:
                    path = 'api/{username}/lights/{id}'.format(
                        username=self.user['name'], id=light['id'])
                    url = 'http://{bridge_ip}/{path}'.format(
                        bridge_ip=self.bridge['ip'], path=path)
                    status, content = request.get(url, resource)
                    _lights.append(content)
                content = _lights
            else:
                content = lights

        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
示例#2
0
    def get(self, resource, debug=False):
        """
        @summary: Get all lights, get new lights, or get a specific light as\
                  determined by the resource object.

        @TODO: Fix resource variable scope issue that manifests when making\
               multiple light.get(resource) calls.
        """
        
        request = Request()
        services = {
            'all':{'service':'lights'},
            'new':{'service':'lights/new'}
        }

        if (isinstance(resource['which'], int)):
            resource['id'] = resource['which']
            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)

        status, content = request.get(url, resource)
        if service == 'lights':
            lights = []
            for (k, v) in content.items():
                v['id'] = int(k)
                lights.append(v)
            if resource.has_key('verbose') and resource['verbose']:
                _lights = []
                for light in lights:
                    path = 'api/{username}/lights/{id}'.format(
                                                                  username=self.user['name'],
                                                                  id=light['id']
                                                              )
                    url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'],
                                                     path=path)
                    status, content = request.get(url, resource)
                    _lights.append(content)
                content = _lights
            else:
                content = lights


        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
示例#3
0
    def get(self, resource, debug=False):
        """

        """

        request = Request()
        services = {
            'all': {'service': 'schedules'}
        }

        if (isinstance(resource['which'], int)):
            resource['id'] = resource['which']
            resource['which'] = 'one'
        if (resource['which'] == 'one'):
            services['one'] = {'service': 'schedules/{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)
        status, content = request.get(url)
        if service == 'schedules':
            schedules = []
            for (k, v) in content.items():
                v['id'] = int(k)
                schedules.append(v)
            if 'verbose' in resource and resource['verbose']:
                _schedules = []
                for schedule in schedules:
                    path = 'api/{username}/schedules/{id}'.format(
                        username=self.user['name'],
                        id=schedule['id'])
                    url = 'http://{bridge_ip}/{path}'.format(
                        bridge_ip=self.bridge['ip'],
                        path=path)
                    status, content = request.get(url, resource)
                    _schedules.append(content)
                content = _schedules
            else:
                content = schedules

        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
示例#4
0
    def get(self, resource, debug=False):
        """
        
        """
        
        request = Request()
        services = {
            'all':{'service':'schedules'}
        }

        if (isinstance(resource['which'], int)):
            resource['id'] = resource['which']
            resource['which'] = 'one'
        if (resource['which'] == 'one'):
            services['one'] = {'service':'schedules/{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)
        status, content = request.get(url)
        if service == 'schedules':
            schedules = []
            for (k, v) in content.items():
                v['id'] = int(k)
                schedules.append(v)
            if resource.has_key('verbose') and resource['verbose']:
                _schedules = []
                for schedule in schedules:
                    path = 'api/{username}/schedules/{id}'.format(
                                                                  username=self.user['name'],
                                                                  id=schedule['id']
                                                              )
                    url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'],
                                                     path=path)
                    status, content = request.get(url, resource)
                    _schedules.append(content)
                content = _schedules
            else:
                content = schedules
        
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
示例#5
0
    def get(self, resource, debug=False):
        """

        """

        services = {
            'bridge': {
                'service': '/config'
            },
            'system': {
                'service': ''
            }
        }

        request = Request()
        path = 'api/{username}{service}'.format(
            username=self.user['name'],
            service=services[resource['which']]['service'])
        url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'],
                                                 path=path)

        status, content = request.get(url)
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
示例#6
0
    def get(self, resource, debug=False):
        """

        """

        request = Request()
        services = {'all': {'service': 'groups'}}

        if (isinstance(resource['which'], int)):
            resource['id'] = resource['which']
            resource['which'] = 'one'
        if (resource['which'] == 'one'):
            services['one'] = {
                'service': 'groups/{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)
        status, content = request.get(url, resource)
        if service == 'groups':
            groups = []
            for (k, v) in content.items():
                v['id'] = int(k)
                groups.append(v)
            if resource.has_key('verbose') and resource['verbose']:
                _groups = []
                for group in groups:
                    path = 'api/{username}/groups/{id}'.format(
                        username=self.user['name'], id=group['id'])
                    url = 'http://{bridge_ip}/{path}'.format(
                        bridge_ip=self.bridge['ip'], path=path)
                    status, content = request.get(url, resource)
                    _groups.append(content)
                content = _groups
            else:
                content = groups
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
示例#7
0
    def get(self, debug=False):
        """
        @status: Done
        """

        request = Request()
        url = 'http://www.meethue.com/api/nupnp'
        status, content = request.get(url)

        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
示例#8
0
    def get(self, debug=False):
        """
        @status: Done
        """

        request = Request()
        url = 'http://www.meethue.com/api/nupnp'
        status, content = request.get(url)
        
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
示例#9
0
    def get(self, resource, debug=False):
        """
        
        """

        request = Request()
        services = {"all": {"service": "schedules"}}

        if isinstance(resource["which"], int):
            resource["id"] = resource["which"]
            resource["which"] = "one"
            services["one"] = {"service": "schedules/{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)
        status, content = request.get(url)
        if service == "schedules":
            schedules = []
            for (k, v) in content.items():
                v["id"] = int(k)
                schedules.append(v)
            if resource.has_key("verbose") and resource["verbose"]:
                _schedules = []
                for schedule in schedules:
                    path = "api/{username}/schedules/{id}".format(username=self.user["name"], id=schedule["id"])
                    url = "http://{bridge_ip}/{path}".format(bridge_ip=self.bridge["ip"], path=path)
                    status, content = request.get(url, resource)
                    _schedules.append(content)
                content = _schedules
            else:
                content = schedules

        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
示例#10
0
    def get(self, resource, debug=False):
        """

        """
        
        services = {
            'bridge':{'service':'/config'},
            'system':{'service':''}
        }
        
        request = Request()
        path = 'api/{username}{service}'.format(username=self.user['name'],
                                                service=services[resource['which']]['service'])
        url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'],
                                                 path=path)

        status, content = request.get(url)
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)