Skip to content

Commit cbcd8c0

Browse files
committed
Revert "Fix event stream timeout at session level (#508)"
This reverts commit 696e662.
1 parent 202b749 commit cbcd8c0

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

custom_components/dahua/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from homeassistant.components.tag import async_scan_tag
1313
import hashlib
1414

15-
from aiohttp import ClientError, ClientResponseError, ClientSession, ClientTimeout, TCPConnector
15+
from aiohttp import ClientError, ClientResponseError, ClientSession, TCPConnector
1616
from homeassistant.config_entries import ConfigEntry
1717
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
1818
from homeassistant.exceptions import ConfigEntryNotReady, PlatformNotReady
@@ -98,8 +98,7 @@ def __init__(self, hass: HomeAssistant, events: list, address: str, port: int, r
9898
"""Initialize the coordinator."""
9999
# Self signed certs are used over HTTPS so we'll disable SSL verification
100100
connector = TCPConnector(enable_cleanup_closed=True, ssl=SSL_CONTEXT)
101-
# Disable total timeout for infinite event stream (default 5-minute timeout causes disconnects)
102-
self._session = ClientSession(connector=connector, timeout=ClientTimeout(total=None))
101+
self._session = ClientSession(connector=connector)
103102

104103
# The client used to communicate with Dahua devices
105104
self.client: DahuaClient = DahuaClient(username, password, address, port, rtsp_port, self._session)

custom_components/dahua/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,13 +759,18 @@ async def stream_events(self, on_receive, events: list, channel: int):
759759
"""
760760
# Use codes=[All] for all codes
761761
codes = ",".join(events)
762-
url = "{0}/cgi-bin/eventManager.cgi?action=attach&codes=[{1}]&heartbeat=5".format(self._base, codes)
762+
heartbeat_interval = 5
763+
url = "{0}/cgi-bin/eventManager.cgi?action=attach&codes=[{1}]&heartbeat={2}".format(
764+
self._base, codes, heartbeat_interval
765+
)
763766
if self._username is not None and self._password is not None:
764767
response = None
765768

766769
try:
767770
auth = DigestAuth(self._username, self._password, self._session)
768-
response = await auth.request("GET", url)
771+
# Disable timeout for infinite event stream (fixes 5-minute disconnection)
772+
timeout = aiohttp.ClientTimeout(total=None)
773+
response = await auth.request("GET", url, timeout=timeout)
769774
response.raise_for_status()
770775

771776
# https://docs.aiohttp.org/en/stable/streams.html

0 commit comments

Comments
 (0)