Esempio n. 1
0
    def update(self, resource, debug=False):
        """
        @summary: Rename lights, or set a light's state, as determined by the\
                  resource object.
        """

        request = Request()
        if ('attr' in resource['data']):
            service = 'lights/{id}'.format(id=resource['which'])
            data = resource['data']['attr']
        elif ('state' in resource['data']):
            service = 'lights/{id}/state'.format(id=resource['which'])
            data = resource['data']['state']
        else:
            raise Exception('Unknown data type.')
        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.put(url, data)
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 2
0
    def update(self, resource, debug=False):
        """
        @summary: Rename lights, or set a light's state, as determined by the\
                  resource object.
        """

        request = Request()
        if (resource['data'].has_key('attr')):
            service = 'lights/{id}'.format(id=resource['which'])
            data = resource['data']['attr']
        elif (resource['data'].has_key('state')):
            service = 'lights/{id}/state'.format(id=resource['which'])
            data = resource['data']['state']
        else:
            raise Exception('Unknown data type.')
        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.put(url, data)
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
0
    def create(self, resource, debug=False):

        request = Request()
        path = 'api/{username}/scenes'.format(username=self.user['name'])
        url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'],
                                                 path=path)
        resource['data']['name'] = resource['which']
        status, content = request.post(url, resource['data'])
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 7
0
    def create(self, resource, debug=False):

        request = Request()
        path = 'api/{username}/scenes'.format(username=self.user['name'])
        url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'],
                                                 path=path)
        resource['data']['name'] = resource['which']
        status, content = request.post(url, resource['data'])
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 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)
Esempio n. 9
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)
Esempio n. 10
0
    def update(self, resource, debug=False):
        """

        """

        request = Request()
        path = 'api/{username}/config'.format(username=self.user['name'])
        url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'],
                                                 path=path)
        status, content = request.put(url, resource['data']['attr'])
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 11
0
    def create(self, resource, debug=False):
        """

        """

        request = Request()
        url = 'http://{bridge_ip}/api'.format(bridge_ip=self.bridge['ip'])
        if resource.has_key('user'):
            resource['user']['username'] = resource['user'].pop('name')
            status, content = request.post(url, resource['user'])
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 12
0
    def delete(self, resource, debug=False):

        request = Request()
        service = 'scenes/{id}'.format(id=resource['which'])
        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.delete(url)
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 13
0
    def create(self, resource, debug=False):
        """

        """

        request = Request()
        url = 'http://{bridge_ip}/api'.format(bridge_ip=self.bridge['ip'])
        if 'user' in resource:
            resource['user']['username'] = resource['user'].pop('name')
            status, content = request.post(url, resource['user'])
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 14
0
    def update(self, resource, debug=False):
        """

        """

        request = Request()
        path = 'api/{username}/config'.format(username=self.user['name'])
        url = 'http://{bridge_ip}/{path}'.format(bridge_ip=self.bridge['ip'],
                                                 path=path)
        status, content = request.put(url, resource['data']['attr'])
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 15
0
    def create(self, resource, debug=False):
        """

        """

        request = Request()
        path = "api/{username}/schedules".format(username=self.user["name"])
        url = "http://{bridge_ip}/{path}".format(bridge_ip=self.bridge["ip"], path=path)
        resource["data"]["name"] = resource["which"]
        status, content = request.post(url, resource["data"])
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 16
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)
Esempio n. 17
0
    def delete(self, resource, debug=False):
        """

        """

        request = Request()
        service = "schedules/{id}".format(id=resource["which"])
        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.delete(url)
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 18
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)
Esempio n. 19
0
    def delete(self, resource, debug=False):

        request = Request()
        service = 'scenes/{id}'.format(id=resource['which'])
        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.delete(url)
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 20
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)
Esempio n. 21
0
    def delete(self, resource, debug=False):
        """

        """

        request = Request()
        if 'user' in resource:
            service = 'config/whitelist/{id}'.format(
                id=resource['user']['name'])
        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.delete(url)
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 22
0
    def delete(self, resource, debug=False):
        """

        """

        request = Request()
        if resource.has_key('user'):
            service = 'config/whitelist/{id}'.format(id=resource['user']['name'])
        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.delete(url)
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 23
0
    def find(self, resource, debug=False):
        """
        @summary: Search for new lights.
        """

        request = Request()

        services = {'new': {'service': 'lights'}}

        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.post(url)
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 24
0
    def update(self, resource, debug=False):
        """

        """

        request = Request()
        if resource["data"].has_key("name"):
            service = "groups/{id}".format(id=resource["which"])
        elif resource["data"].has_key("action"):
            service = "groups/{id}/action".format(id=resource["which"])
        else:
            raise Exception("Unknown data type.")
        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.put(url, resource["data"]["action"])
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 25
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)
Esempio n. 26
0
    def update(self, resource, debug=False):
        """

        """

        request = Request()
        if (resource['data'].has_key('name')):
            service = 'groups/{id}'.format(id=resource['which'])
        elif (resource['data'].has_key('action')):
            service = 'groups/{id}/action'.format(id=resource['which'])
        else:
            raise Exception('Unknown data type.')
        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.put(url, resource['data']['action'])
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 27
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)
Esempio n. 28
0
    def update(self, resource, debug=False):
        """

        """

        request = Request()
        if (resource['data'].has_key('name')):
            service = 'groups/{id}'.format(id=resource['which'])
        elif (resource['data'].has_key('action')):
            service = 'groups/{id}/action'.format(id=resource['which'])
        else:
            raise Exception('Unknown data type.')
        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.put(url, resource['data']['action'])
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)
Esempio n. 29
0
    def find(self, resource, debug=False):
        """
        @summary: Search for new lights.
        """
        
        request = Request()
        
        services = {
            'new':{'service':'lights'}
        }
        
        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.post(url)
        if debug:
            return dict(info=status, resource=content)
        else:
            return dict(resource=content)