Exemplo n.º 1
0
    def authenticate(self, tries=AUTH_FAILURE_RETRIES):
        path = "http://%s/api" % (
            self.station_ip
        )

        ## Needs more error checking, currently assumes connection will work
        ## and that returns proper json.
        auth = {
            "devicetype": self.devicetype,
            "username": self.client_identifier
        }

        resp = requests.post(path, data=json.dumps(auth))
        logger.debug(resp)
        logger.debug(resp.content)

        resp = json.loads(resp.content)

        logger.debug(resp)

        trigger_event("hue:auth_required")
        logger.warn("Time to go press your button!")

        if isinstance(resp, list) and resp[0].get("error", None):
            logger.debug(resp[0]["error"])
            if tries:
                sleep(AUTH_FAILURE_SLEEP)
                self.authenticate()
            else:
                raise TooManyFailures()

        return True
Exemplo n.º 2
0
    def update_state_cache(self, values=None, quiet=False):
        if not values:
            values = self.hue.request(path="/lights/%s" % self.light_id)

        if values != self.state:
            if not quiet:
                trigger_event("hue:bulb:state_change:%s" % self.light_id, self.light_id, values)
            self.state.update(values)

        self.last_status_time = datetime.datetime.now()
Exemplo n.º 3
0
def shutdown_group_vms(previous, config_id):

    config = VmomiConfig.objects.get(pk=config_id)
    devices = get_service_instances(config)

    vms = []
    for host, service_instance in devices.items():
        if service_instance:
            vms.extend(get_vms(service_instance))
    shutdown_vms(vms)
    
    trigger_event(config.group.name,'all_vms_shutdown')
Exemplo n.º 4
0
def event(request, group, event):
    trigger_event(group, event)
    results = {'results': 'success'}
    return JsonResponse(results)