Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ariston/ariston_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,11 @@ async def __async_request(
params,
)

async with aiohttp.ClientSession() as session:
# Apply an explicit total timeout so a stalled request fails fast
# instead of relying on aiohttp's 5 minute default. This mirrors the
# 30 second timeout used by the synchronous `requests` path.
timeout = aiohttp.ClientTimeout(total=30)
async with aiohttp.ClientSession(timeout=timeout) as session:
Comment thread
astrinh0 marked this conversation as resolved.
Resolved
response = await session.request(
method, path, params=params, json=body, headers=headers
)
Expand Down
10 changes: 9 additions & 1 deletion tests/test_ariston_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import unittest
from unittest.mock import AsyncMock, patch

import aiohttp

from ariston.ariston_api import AristonAPI, ConnectionException
from ariston.const import (
BsbOperativeMode,
Expand Down Expand Up @@ -127,9 +129,15 @@ async def connect_and_discover():
with patch(
"ariston.ariston_api.aiohttp.ClientSession",
side_effect=[login_session, devices_session],
):
) as client_session:
devices = asyncio.run(connect_and_discover())

# Every async request must set an explicit total timeout instead of
# relying on aiohttp's 5 minute default.
self.assertEqual(client_session.call_count, 2)
for call in client_session.call_args_list:
self.assertEqual(call.kwargs["timeout"], aiohttp.ClientTimeout(total=30))

self.assertEqual(devices, [{"gw": "gateway-1"}])
self.assertEqual(
login_session.calls[0][0],
Expand Down
Loading