From 755bf92c907d62086dd971d612271ea4adbdcafd Mon Sep 17 00:00:00 2001 From: ryt51V Date: Sat, 23 Aug 2025 19:36:14 +0100 Subject: [PATCH] Increase v6 timeouts and allow changing them --- hole/v6.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hole/v6.py b/hole/v6.py index eacc4a1..79d0c2d 100644 --- a/hole/v6.py +++ b/hole/v6.py @@ -34,6 +34,7 @@ def __init__( verify_tls: bool = True, password: Optional[str] = None, port: Optional[int] = None, + timeout: int = 15, ): """Initialize the connection to a Pi-hole instance.""" if protocol not in ["http", "https"]: @@ -47,6 +48,7 @@ def __init__( self.host = host self.location = location.strip("/") # Remove any trailing slashes self.password = password + self.timeout = timeout self._session_id = None self._session_validity = None self._csrf_token = None @@ -83,7 +85,7 @@ async def authenticate(self): auth_url = f"{self.base_url}/api/auth" try: - async with async_timeout.timeout(5): + async with async_timeout.timeout(self.timeout): response = await self._session.post( auth_url, json={"password": str(self.password)}, ssl=self.verify_tls ) @@ -147,7 +149,7 @@ async def logout(self): headers = {"X-FTL-SID": self._session_id} try: - async with async_timeout.timeout(5): + async with async_timeout.timeout(self.timeout): await self._session.delete( logout_url, headers=headers, ssl=self.verify_tls ) @@ -183,7 +185,7 @@ async def _fetch_data(self, endpoint: str, params=None) -> dict: headers["X-FTL-CSRF"] = self._csrf_token try: - async with async_timeout.timeout(5): + async with async_timeout.timeout(self.timeout): response = await self._session.get( url, params=params, headers=headers, ssl=self.verify_tls ) @@ -249,7 +251,7 @@ async def enable(self): payload = {"blocking": True, "timer": None} try: - async with async_timeout.timeout(5): + async with async_timeout.timeout(self.timeout): response = await self._session.post( url, json=payload, headers=headers, ssl=self.verify_tls ) @@ -294,7 +296,7 @@ async def disable(self, duration=0): payload = {"blocking": False, "timer": duration if duration > 0 else None} try: - async with async_timeout.timeout(5): + async with async_timeout.timeout(self.timeout): response = await self._session.post( url, json=payload, headers=headers, ssl=self.verify_tls )