55from types import TracebackType
66from typing import Any , Dict , List , Optional , Type , Union
77
8- import aiohttp
98import humps
10- from aiohttp import ClientResponse
9+ from aiohttp import ClientResponse , ClientSession
1110
1211from pyhoma .exceptions import BadCredentialsException , TooManyRequestsException
1312from pyhoma .models import Command , Device , Event , Execution , Scenario , State
2019class TahomaClient :
2120 """ Interface class for the Tahoma API """
2221
23- def __init__ (self , username : str , password : str , api_url : str = API_URL ) -> None :
22+ def __init__ (
23+ self ,
24+ username : str ,
25+ password : str ,
26+ api_url : str = API_URL ,
27+ session : ClientSession = None ,
28+ ) -> None :
2429 """
2530 Constructor
2631
2732 :param username: the username for Tahomalink.com
2833 :param password: the password for Tahomalink.com
34+ :param api_url: optional custom api url
35+ :param session: optional ClientSession
2936 """
3037
3138 self .username = username
@@ -36,7 +43,7 @@ def __init__(self, username: str, password: str, api_url: str = API_URL) -> None
3643 self .__roles = None
3744 self .event_listener_id : Optional [str ] = None
3845
39- self .session = aiohttp . ClientSession ()
46+ self .session = session if session else ClientSession ()
4047
4148 async def __aenter__ (self ) -> TahomaClient :
4249 return self
0 commit comments