Example #1
0
    def __init__(self, clientId, clientSecret, username, password, scope,
                 app_version, user_prefix):
        postParams = {
            "grant_type": "password",
            "client_id": clientId,
            "client_secret": clientSecret,
            "username": username,
            "password": password,
            "scope": scope,
        }

        if user_prefix:
            postParams.update({"user_prefix": user_prefix})
        if app_version:
            postParams.update({"app_version": app_version})

        resp = postRequest(_AUTH_REQ, postParams)
        self._clientId = clientId
        self._clientSecret = clientSecret
        try:
            self._accessToken = resp["access_token"]
        except (KeyError):
            LOG.error("Netatmo API returned %s", resp["error"])
            raise NoDevice("Authentication against Netatmo API failed")
        self.refreshToken = resp["refresh_token"]
        self._scope = resp["scope"]
        self.expiration = int(resp["expire_in"] + time.time() - 1800)
    def __init__(self,
                 clientId=_CLIENT_ID,
                 clientSecret=_CLIENT_SECRET,
                 username=_USERNAME,
                 password=_PASSWORD,
                 scope=_SCOPE,
                 app_version=_APP_VERSION,
                 user_prefix=_USER_PREFIX):
        postParams = {
            "grant_type": "password",
            "client_id": clientId,
            "client_secret": clientSecret,
            "username": username,
            "password": password,
            "scope": scope
        }

        if user_prefix:
            postParams.update({"user_prefix": user_prefix})
        if app_version:
            postParams.update({"app_version": app_version})
        resp = postRequest(_AUTH_REQ, postParams)
        self._clientId = clientId
        self._clientSecret = clientSecret
        self._accessToken = resp['access_token']
        self.refreshToken = resp['refresh_token']
        self._scope = resp['scope']
        self.expiration = int(resp['expire_in'] + time.time() - 1800)
Example #3
0
 def __init__(self, authData):
     postParams = {
             "access_token" : authData.accessToken
             }
     resp = postRequest(_GETSTATIONDATA_REQ, postParams)
     self.rawData = resp['body']
     self.devList = self.rawData['devices']
     self.ownerMail = self.rawData['user']['mail']
Example #4
0
 def addwebhook(self, webhook_url):
     postParams = {
         "access_token": self._accessToken,
         "url": webhook_url,
         "app_types": "app_security",
     }
     resp = postRequest(_WEBHOOK_URL_ADD, postParams)
     LOG.debug("addwebhook: %s", resp)
Example #5
0
 def __init__(self, authData):
     postParams = {
             "access_token" : authData.accessToken
             }
     resp = postRequest(_GETSTATIONDATA_REQ, postParams)
     self.rawData = resp['body']
     self.devList = self.rawData['devices']
     self.ownerMail = self.rawData['user']['mail']
Example #6
0
    def accessToken(self):

        if self.expiration < time.time():  # Token should be renewed
            postParams = {
                "grant_type": "refresh_token",
                "refresh_token": self.refreshToken,
                "client_id": self._clientId,
                "client_secret": self._clientSecret,
            }
            resp = postRequest(_AUTH_REQ, postParams)
            self._accessToken = resp["access_token"]
            self.refreshToken = resp["refresh_token"]
            self.expiration = int(resp["expire_in"] + time.time() - 1800)
        return self._accessToken
Example #7
0
    def accessToken(self):

        if self.expiration < time.time():  # Token should be renewed
            postParams = {
                "grant_type": "refresh_token",
                "refresh_token": self.refreshToken,
                "client_id": self._clientId,
                "client_secret": self._clientSecret,
            }
            resp = postRequest(_AUTH_REQ, postParams)
            self._accessToken = resp["access_token"]
            self.refreshToken = resp["refresh_token"]
            self.expiration = int(resp["expire_in"] + time.time() - 1800)
        return self._accessToken
Example #8
0
 def __init__(self, clientId=_CLIENT_ID,
                    clientSecret=_CLIENT_SECRET,
                    username=_USERNAME,
                    password=_PASSWORD,
                    scope="read_station"):
     postParams = {
             "grant_type": "password",
             "client_id": clientId,
             "client_secret": clientSecret,
             "username": username,
             "password": password,
             "scope": scope
             }
     resp = postRequest(_AUTH_REQ, postParams)
     self._clientId = clientId
     self._clientSecret = clientSecret
     self._accessToken = resp['access_token']
     self.refreshToken = resp['refresh_token']
     self._scope = resp['scope']
     self.expiration = int(resp['expire_in'] + time.time() - 1800)
Example #9
0
 def __init__(self, clientId=_CLIENT_ID,
                    clientSecret=_CLIENT_SECRET,
                    username=_USERNAME,
                    password=_PASSWORD,
                    scope="read_station"):
     postParams = {
             "grant_type": "password",
             "client_id": clientId,
             "client_secret": clientSecret,
             "username": username,
             "password": password,
             "scope": scope
             }
     resp = postRequest(_AUTH_REQ, postParams)
     self._clientId = clientId
     self._clientSecret = clientSecret
     self._accessToken = resp['access_token']
     self.refreshToken = resp['refresh_token']
     self._scope = resp['scope']
     self.expiration = int(resp['expire_in'] + time.time() - 1800)
Example #10
0
 def __init__(self, authData):
     postParams = {"access_token": authData.accessToken}
     resp = postRequest(_GETSTATIONDATA_REQ, postParams)
     self.rawData = resp["body"]
     self.devList = self.rawData["devices"]
     self.ownerMail = self.rawData["user"]["mail"]
Example #11
0
 def dropwebhook(self):
     postParams = {"access_token": self._accessToken, "app_types": "app_security"}
     resp = postRequest(_WEBHOOK_URL_DROP, postParams)
     LOG.debug("dropwebhook: %s", resp)
Example #12
0
 def __init__(self, authData):
     postParams = {"access_token": authData.accessToken}
     resp = postRequest(_GETSTATIONDATA_REQ, postParams)
     self.rawData = resp["body"]
     self.devList = self.rawData["devices"]
     self.ownerMail = self.rawData["user"]["mail"]