From ec3ecdb44a68eaec2849dab463e4b0bc60ad3389 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 11 Sep 2019 11:09:35 +0200 Subject: [PATCH] Add logout function (#7) --- .devcontainer/devcontainer.json | 2 +- connect_box/__init__.py | 8 ++++++++ example.py | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 0e8bd80..f4aeb13 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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 .", diff --git a/connect_box/__init__.py b/connect_box/__init__.py index a1f0151..1216ae8 100644 --- a/connect_box/__init__.py +++ b/connect_box/__init__.py @@ -16,6 +16,7 @@ HTTP_HEADER_X_REQUESTED_WITH = "X-Requested-With" CMD_LOGIN = 15 +CMD_LOGOUT = 16 CMD_DEVICES = 123 @@ -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: diff --git a/example.py b/example.py index 456f60a..532cc65 100644 --- a/example.py +++ b/example.py @@ -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())