コード例 #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)
コード例 #2
0
ファイル: _light.py プロジェクト: allanbunch/beautifulhue
    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)
コード例 #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)
コード例 #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)
コード例 #5
0
ファイル: _light.py プロジェクト: Edinunzio/beautifulhue
    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)
コード例 #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)
コード例 #7
0
ファイル: _scene.py プロジェクト: allanbunch/beautifulhue
    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)
コード例 #8
0
ファイル: _portal.py プロジェクト: Edinunzio/beautifulhue
    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
ファイル: _portal.py プロジェクト: t7reyeslua/HueBeats
    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)
コード例 #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)
コード例 #11
0
ファイル: _config.py プロジェクト: Edinunzio/beautifulhue
    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)
コード例 #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)
コード例 #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)
コード例 #14
0
ファイル: _config.py プロジェクト: Edinunzio/beautifulhue
    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)
コード例 #15
0
ファイル: _schedule.py プロジェクト: Edinunzio/beautifulhue
    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)
コード例 #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)
コード例 #17
0
ファイル: _schedule.py プロジェクト: Edinunzio/beautifulhue
    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)
コード例 #18
0
ファイル: _schedule.py プロジェクト: allanbunch/beautifulhue
    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)
コード例 #19
0
ファイル: _scene.py プロジェクト: allanbunch/beautifulhue
    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)
コード例 #20
0
ファイル: _group.py プロジェクト: t7reyeslua/HueBeats
    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)
コード例 #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)
コード例 #22
0
ファイル: _config.py プロジェクト: Edinunzio/beautifulhue
    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)
コード例 #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)
コード例 #24
0
ファイル: _group.py プロジェクト: will-mooney-3/beautifulhue
    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)
コード例 #25
0
ファイル: _config.py プロジェクト: Edinunzio/beautifulhue
    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)
コード例 #26
0
ファイル: _group.py プロジェクト: t7reyeslua/HueBeats
    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)
コード例 #27
0
ファイル: _schedule.py プロジェクト: Edinunzio/beautifulhue
    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)
コード例 #28
0
ファイル: _group.py プロジェクト: Edinunzio/beautifulhue
    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)
コード例 #29
0
ファイル: _light.py プロジェクト: allanbunch/beautifulhue
    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)