Skip to content

Commit 2df6a06

Browse files
authored
Add unregister endpoint and automatically unregister on close (#25)
1 parent 1701e04 commit 2df6a06

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tahoma_api/client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def __init__(self, username: str, password: str, api_url: str = API_URL) -> None
3434

3535
self.devices: List[Device] = []
3636
self.__roles = None
37+
self.event_listener_id: Optional[str] = None
3738

3839
self.session = aiohttp.ClientSession()
3940

@@ -50,6 +51,9 @@ async def __aexit__(
5051

5152
async def close(self) -> None:
5253
"""Close the session."""
54+
if self.event_listener_id:
55+
await self.unregister_event_listener(self.event_listener_id)
56+
5357
await self.session.close()
5458

5559
async def login(self) -> bool:
@@ -103,6 +107,7 @@ async def register_event_listener(self) -> str:
103107
"""
104108
response = await self.__post("events/register")
105109
listener_id = response.get("id")
110+
self.event_listener_id = listener_id
106111

107112
return listener_id
108113

@@ -118,6 +123,14 @@ async def fetch_event_listener(self, listener_id: str) -> List[Event]:
118123

119124
return events
120125

126+
async def unregister_event_listener(self, listener_id: str) -> None:
127+
"""
128+
Unregister an event listener.
129+
API response status is always 200, even on unknown listener ids.
130+
"""
131+
await self.__post(f"events/{listener_id}/unregister")
132+
self.event_listener_id = None
133+
121134
async def get_current_execution(self, exec_id: str) -> Execution:
122135
""" Get an action group execution currently running """
123136
response = await self.__get(f"exec/current/{exec_id}")

0 commit comments

Comments
 (0)