Esempio 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
Esempio 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()