diff --git a/src/saic_ismart_client_ng/api/base.py b/src/saic_ismart_client_ng/api/base.py index 7e382c0..eb46db6 100644 --- a/src/saic_ismart_client_ng/api/base.py +++ b/src/saic_ismart_client_ng/api/base.py @@ -53,6 +53,9 @@ def __init__( self.__api_client = SaicApiClient(configuration, listener=listener) self.__token_expiration: datetime.datetime | None = None + async def close(self) -> None: + await self.__api_client.close() + async def login(self) -> LoginResp: headers = { "Content-Type": "application/x-www-form-urlencoded", diff --git a/src/saic_ismart_client_ng/net/client/__init__.py b/src/saic_ismart_client_ng/net/client/__init__.py index 172ae61..af19147 100644 --- a/src/saic_ismart_client_ng/net/client/__init__.py +++ b/src/saic_ismart_client_ng/net/client/__init__.py @@ -38,6 +38,9 @@ def __init__( async def send(self, request: Request) -> Response: return await self.__client.send(request) + async def close(self) -> None: + await self.__client.aclose() + @property def user_token(self) -> str: return self.__user_token diff --git a/tests/test_close.py b/tests/test_close.py new file mode 100644 index 0000000..d0012fe --- /dev/null +++ b/tests/test_close.py @@ -0,0 +1,13 @@ +import unittest + +from saic_ismart_client_ng import SaicApi +from saic_ismart_client_ng.model import SaicApiConfiguration + + +class TestClose(unittest.IsolatedAsyncioTestCase): + async def test_close_is_idempotent(self) -> None: + api = SaicApi( + SaicApiConfiguration(username="user", password="pass"), + ) + await api.close() + await api.close()