Skip to content

Commit

Permalink
Add logout function (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvizeli authored Sep 11, 2019
1 parent 325c253 commit ec3ecdb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
{
"name": "PyDroid IPCam dev",
"name": "Connect-Box dev",
"context": "..",
"dockerFile": "Dockerfile",
"postCreateCommand": "pip3 install -e .",
Expand Down
8 changes: 8 additions & 0 deletions connect_box/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
HTTP_HEADER_X_REQUESTED_WITH = "X-Requested-With"

CMD_LOGIN = 15
CMD_LOGOUT = 16
CMD_DEVICES = 123


Expand Down Expand Up @@ -76,6 +77,13 @@ async def async_get_devices(self) -> List[Device]:

return self.devices

async def async_logout(self) -> None:
"""Logout and close session."""
if not self.token:
return

await self._async_ws_function(CMD_LOGOUT)

async def async_initialize_token(self) -> None:
"""Get the token first."""
try:
Expand Down
2 changes: 2 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ async def main():
await client.async_get_devices()
print(client.devices)

await client.async_logout()


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

0 comments on commit ec3ecdb

Please sign in to comment.