Skip to content

Commit fab2e57

Browse files
authored
Support adding a custom session (#37)
* Support adding a custom session * Import ClientSession directly
1 parent 7213353 commit fab2e57

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pyhoma/client.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from types import TracebackType
66
from typing import Any, Dict, List, Optional, Type, Union
77

8-
import aiohttp
98
import humps
10-
from aiohttp import ClientResponse
9+
from aiohttp import ClientResponse, ClientSession
1110

1211
from pyhoma.exceptions import BadCredentialsException, TooManyRequestsException
1312
from pyhoma.models import Command, Device, Event, Execution, Scenario, State
@@ -20,12 +19,20 @@
2019
class 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

Comments
 (0)