コード例 #1
0
ファイル: TedeeClient.py プロジェクト: konradsikorski/pytedee
    def unlock(self, id):
        '''Unlock method'''
        for lock in self._sensor_list:
            if id == lock.get_id():
                payload = {"deviceId": id}
                break
        if payload == None:
            raise TedeeClientException("This Id not found")

        if (self.is_token_valid() == False):
            self.get_token()

        if (self.is_token_valid() == True):
            r = requests.post(api_url_open,
                              headers=self._api_header,
                              data=json.dumps(payload),
                              timeout=self._timeout)

            success = r.json()["success"]
            if success:
                lock.set_state(2)
                _LOGGER.debug("unlock command successful, id: %d ", id)

                t = Timer(2, self.get_state)
                t.start()
コード例 #2
0
ファイル: TedeeClient.py プロジェクト: konradsikorski/pytedee
    def get_token(self, **kwargs):
        self._have_token = False
        auth_parameters["username"] = self._username
        auth_parameters["password"] = self._password
        self._token = None
        r = requests.post(auth_url,
                          params=auth_parameters,
                          headers=auth_header,
                          timeout=self._timeout)
        try:
            self._token = r.json()["access_token"]
            #_LOGGER.error("result: %s", r.json())
            _LOGGER.debug("Got new token.")
        except KeyError:
            raise TedeeClientException("Authentication not successfull")
        '''Create the api header with new token'''
        self._api_header = {
            "Content-Type": "application/json",
            "Authorization": "Bearer " + self._token
        }
        '''Store the date when actual token expires'''
        expires = int(r.json()["expires_in"])

        self._token_valid_until = datetime.datetime.now() + datetime.timedelta(
            seconds=expires)
        _LOGGER.debug("Token valid until: %s", self._token_valid_until)
コード例 #3
0
ファイル: TedeeClient.py プロジェクト: konradsikorski/pytedee
 def get_battery(self, id):
     for lock in self._sensor_list:
         if id == lock.get_id():
             payload = {"deviceId": id}
             break
     if payload == None:
         raise TedeeClientException("This Id not found")
     api_url_battery = "https://api.tedee.com/api/v1.15/my/device/" + str(
         id) + "/battery"
     r = requests.get(api_url_battery,
                      headers=self._api_header,
                      timeout=self._timeout)
     _LOGGER.debug("result: %s", r.json())
     result = r.json()["result"]
     try:
         success = r.json()["success"]
         if success:
             for lock in self._sensor_list:
                 if id == lock.get_id():
                     lock.set_battery_level(result["level"])
                     _LOGGER.debug("id: %d, battery level: %d", id,
                                   lock.get_battery_level())
         return success
     except KeyError:
         _LOGGER.error("result: %s", r.json())
         return False
コード例 #4
0
    def get_devices(self):
        '''Get the list of registered locks'''
        api_url_lock = "https://api.tedee.com/api/v1.15/my/lock"
        r = requests.get(api_url_lock, headers=self._api_header,
            timeout=self._timeout)
        _LOGGER.debug("Locks %s", r.json())
        result = r.json()["result"]

        for x in result:            
            id = x["id"]
            name = x["name"]
            isConnected = x["isConnected"]
            state = x["lockProperties"]["state"]
            batteryLevel = x["lockProperties"]["batteryLevel"]
            isCharging = x["lockProperties"]["isCharging"]
            isEnabledPullSpring =x["deviceSettings"]["pullSpringEnabled"]
            durationPullSpring =x["deviceSettings"]["pullSpringDuration"]
            
            lock = Lock(name, id)
            lock.set_connected(isConnected)
            lock.set_state(state)
            lock.set_battery_level(batteryLevel)
            lock.set_is_charging(isCharging)
            lock.set_is_enabled_pullspring(isEnabledPullSpring)
            lock.set_duration_pullspring(durationPullSpring)
            
            self._lock_id = id
            '''store the found lock in _sensor_list and get the battery_level'''

            self._sensor_list.append(lock)

        if self._lock_id == None:
            raise TedeeClientException("No lock found")
コード例 #5
0
ファイル: TedeeClient.py プロジェクト: konradsikorski/pytedee
 def is_locked(self, id):
     for lock in self._sensor_list:
         if id == lock.get_id():
             payload = {"deviceId": id}
             break
     if payload == None:
         raise TedeeClientException("This Id not found")
     return lock.get_state() == 6
コード例 #6
0
ファイル: TedeeClient.py プロジェクト: konradsikorski/pytedee
 def get_devices(self):
     '''Get the list of registered locks'''
     api_url_lock = "https://api.tedee.com/api/v1.15/my/lock"
     r = requests.get(api_url_lock,
                      headers=self._api_header,
                      timeout=self._timeout)
     _LOGGER.debug("Locks %s", r.json())
     result = r.json()["result"]
     for x in result:
         id = x["id"]
         name = x["name"]
         self._lock_id = id
         '''store the found lock in _sensor_list and get the battery_level'''
         self._sensor_list.append(Lock(name, id))
         self.get_battery(id)
     if self._lock_id == None:
         raise TedeeClientException("No lock found")
コード例 #7
0
ファイル: TedeeClient.py プロジェクト: joerg65/pytedee
 def find_lock(self, id):
     for lock in self._sensor_list:
         if id == lock.get_id():
             return lock
     raise TedeeClientException("This Id not found")