Skip to content
Open
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
12 changes: 7 additions & 5 deletions hole/v6.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand All @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down