Skip to content
Draft
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
56 changes: 56 additions & 0 deletions pyoverkiz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,59 @@
This package provides models, enums and a client to communicate with the
Overkiz cloud and local gateway APIs.
"""

from pyoverkiz.auth import (
Credentials,
LocalTokenCredentials,
RexelOAuthCodeCredentials,
TokenCredentials,
UsernamePasswordCredentials,
)
Comment on lines +7 to +13
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing credential classes from pyoverkiz.auth pulls in pyoverkiz.auth.factory and pyoverkiz.auth.strategies (via pyoverkiz/auth/__init__.py), which imports heavy optional runtime deps like boto3 at module import time. That makes a plain import pyoverkiz significantly heavier than necessary for users who only need models/exceptions. Prefer importing these symbols directly from pyoverkiz.auth.credentials (or use a lazy re-export via __getattr__) to keep top-level imports lightweight.

Copilot uses AI. Check for mistakes.
from pyoverkiz.client import OverkizClient
from pyoverkiz.exceptions import (
Comment on lines +14 to +15
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-exporting OverkizClient from the package root forces pyoverkiz/client.py to be imported on every import pyoverkiz. That module creates SSL_CONTEXT_LOCAL_API at import time, which loads the bundled CA cert from disk (blocking I/O). Consider making the client import lazy (PEP 562 __getattr__) and/or moving SSL context creation behind a lazy getter so importing the package doesn’t perform file I/O.

Copilot uses AI. Check for mistakes.
BadCredentialsException,
BaseOverkizException,
MaintenanceException,
NotAuthenticatedException,
OverkizException,
TooManyRequestsException,
)
from pyoverkiz.models import (
Action,
ActionGroup,
Command,
Device,
Event,
Execution,
Gateway,
Place,
ServerConfig,
Setup,
State,
)

__all__ = [
"Action",
"ActionGroup",
"BadCredentialsException",
"BaseOverkizException",
"Command",
"Credentials",
"Device",
"Event",
"Execution",
"Gateway",
"LocalTokenCredentials",
"MaintenanceException",
"NotAuthenticatedException",
"OverkizClient",
"OverkizException",
"Place",
"RexelOAuthCodeCredentials",
"ServerConfig",
"Setup",
"State",
"TokenCredentials",
"TooManyRequestsException",
"UsernamePasswordCredentials",
]
Comment on lines +37 to +61
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New top-level re-exports/__all__ are part of the public API, but there’s no test asserting these names are importable from pyoverkiz (e.g., from pyoverkiz import OverkizClient, Credentials, Action). Adding a small importability test would prevent accidental breakage and ensure __all__ stays in sync with actual exports.

Copilot uses AI. Check for mistakes.
14 changes: 13 additions & 1 deletion pyoverkiz/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ async def refresh_listener(invocation: Details) -> None:
await _get_client_from_invocation(invocation).register_event_listener()


# Reusable backoff decorators to reduce code duplication
# Reusable backoff decorators with max_tries and max_time to cap total retry duration.
retry_on_auth_error = backoff.on_exception(
backoff.expo,
(NotAuthenticatedException, ServerDisconnectedError),
max_tries=2,
max_time=60,
jitter=backoff.full_jitter,
on_backoff=relogin,
logger=_LOGGER,
)
Expand All @@ -84,27 +86,35 @@ async def refresh_listener(invocation: Details) -> None:
backoff.expo,
(TimeoutError, ClientConnectorError),
max_tries=5,
max_time=120,
jitter=backoff.full_jitter,
logger=_LOGGER,
)

retry_on_concurrent_requests = backoff.on_exception(
backoff.expo,
TooManyConcurrentRequestsException,
max_tries=5,
max_time=120,
jitter=backoff.full_jitter,
logger=_LOGGER,
)

retry_on_too_many_executions = backoff.on_exception(
backoff.expo,
TooManyExecutionsException,
max_tries=10,
max_time=300,
jitter=backoff.full_jitter,
logger=_LOGGER,
)

retry_on_listener_error = backoff.on_exception(
backoff.expo,
(InvalidEventListenerIdException, NoRegisteredEventListenerException),
max_tries=2,
max_time=30,
jitter=backoff.full_jitter,
on_backoff=refresh_listener,
logger=_LOGGER,
)
Expand All @@ -113,6 +123,8 @@ async def refresh_listener(invocation: Details) -> None:
backoff.expo,
ExecutionQueueFullException,
max_tries=5,
max_time=120,
jitter=backoff.full_jitter,
logger=_LOGGER,
)

Expand Down
Loading