Skip to content

Commit

Permalink
Add logout method (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentame authored Oct 20, 2020
1 parent 4132155 commit c9b8de0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/synology_dsm/synology_dsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def apis(self):
"""Gets available API infos from the NAS."""
return self._apis

def login(self, otp_code: str = None):
def login(self, otp_code: str = None) -> bool:
"""Create a logged session."""
# First reset the session
self._debuglog("Creating new session")
Expand Down Expand Up @@ -176,7 +176,13 @@ def login(self, otp_code: str = None):
self._information = SynoDSMInformation(self)
self._information.update()

return True
return result["success"]

def logout(self) -> bool:
"""Log out of the session."""
result = self.get(API_AUTH, "logout")
self._session = None
return result["success"]

@property
def device_token(self) -> str:
Expand Down
2 changes: 2 additions & 0 deletions tests/api_data/dsm_6/const_6_api_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
},
"success": True,
}

DSM_6_AUTH_LOGOUT = {"success": True}

0 comments on commit c9b8de0

Please sign in to comment.