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
16 changes: 16 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ uv add pyoverkiz
pip install pyoverkiz
```

### Optional extras

Some servers require additional dependencies that are not installed by default:

| Extra | Server | Packages |
|-------|--------|----------|
| `nexity` | Nexity | boto3, warrant-lite |

Install an extra with:

```bash
uv add "pyoverkiz[nexity]"
# or
pip install "pyoverkiz[nexity]"
```

## Choose your server

Use a cloud server when you want to connect through the vendor’s public API. Use a local server when you want LAN access to a gateway.
Expand Down
2 changes: 1 addition & 1 deletion docs/migration-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,4 @@ These are not breaking, but worth knowing about when migrating:
- **Device helpers** — `Device.get_command_definition()` for looking up command metadata.
- **Reference endpoints** — query server metadata: `get_reference_ui_classes()`, `get_reference_ui_widgets()`, `get_reference_ui_profile()`, `get_reference_controllable_types()`, etc.
- **Firmware management** — `get_devices_not_up_to_date()`, `get_device_firmware_status()`, `update_device_firmware()`.
- **boto3 lazy import** — `boto3` is only imported when the Nexity auth strategy is actually used.
- **Optional Nexity dependencies** — `boto3` and `warrant-lite` are no longer installed by default. Install them with `pip install pyoverkiz[nexity]` if you use the Nexity server. A clear `ImportError` is raised at login time if the extra is missing.
21 changes: 12 additions & 9 deletions pyoverkiz/auth/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import ssl
from collections.abc import Mapping
from http import HTTPStatus
from typing import TYPE_CHECKING, Any, cast

if TYPE_CHECKING:
from botocore.client import BaseClient
from typing import Any, cast

from aiohttp import ClientSession, FormData

Expand Down Expand Up @@ -246,14 +243,20 @@ class NexityAuthStrategy(SessionLoginStrategy):

async def login(self) -> None:
"""Perform login using Nexity username and password."""
import boto3
from botocore.config import Config
from botocore.exceptions import ClientError
from warrant_lite import WarrantLite
try:
import boto3
from botocore.config import Config
from botocore.exceptions import ClientError
from warrant_lite import WarrantLite
except ImportError as err:
raise ImportError(
"Nexity authentication requires the 'nexity' extra. "
"Install it with: pip install pyoverkiz[nexity]"
) from err

loop = asyncio.get_running_loop()

def _client() -> BaseClient:
def _client() -> Any:
return boto3.client(
"cognito-idp", config=Config(region_name=NEXITY_COGNITO_REGION)
)
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ dependencies = [
"aiohttp<4.0.0,>=3.10.3",
"backoff<3.0,>=1.10.0",
"attrs>=21.2",
"boto3<2.0.0,>=1.18.59",
"warrant-lite<2.0.0,>=1.0.4",
"cattrs>=23.2",
]

[project.optional-dependencies]
nexity = [
"boto3<2.0.0,>=1.18.59",
"warrant-lite<2.0.0,>=1.0.4",
]
docs = [
"mkdocs>=1.5.0,<2.0",
"mkdocs-material>=9.5.0",
Expand Down
31 changes: 30 additions & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@

import pytest
from aiohttp import ClientSession
from botocore.exceptions import ClientError

try:
from botocore.exceptions import ClientError

HAS_NEXITY_DEPS = True
except ImportError:
HAS_NEXITY_DEPS = False

from pyoverkiz.auth.base import AuthContext
from pyoverkiz.auth.credentials import (
Expand Down Expand Up @@ -499,6 +505,28 @@ def test_boto3_not_imported_at_module_load(self):
sys.modules[mod] = value

@pytest.mark.asyncio
async def test_login_raises_import_error_without_nexity_extra(self):
"""Login raises ImportError with install hint when nexity extra is missing."""
server_config = ServerConfig(
server=Server.NEXITY,
name="Nexity",
endpoint="https://api.nexity.com",
manufacturer="Nexity",
api_type=APIType.CLOUD,
)
credentials = UsernamePasswordCredentials("user", "pass")
session = AsyncMock(spec=ClientSession)

strategy = NexityAuthStrategy(credentials, session, server_config, True)

with (
patch.dict(sys.modules, {"boto3": None}),
pytest.raises(ImportError, match="pyoverkiz\\[nexity\\]"),
):
await strategy.login()

@pytest.mark.asyncio
@pytest.mark.skipif(not HAS_NEXITY_DEPS, reason="nexity extra not installed")
async def test_login_maps_invalid_credentials_client_error(self):
"""Map Cognito bad-credential errors to NexityBadCredentialsError."""
server_config = ServerConfig(
Expand Down Expand Up @@ -527,6 +555,7 @@ async def test_login_maps_invalid_credentials_client_error(self):
await strategy.login()

@pytest.mark.asyncio
@pytest.mark.skipif(not HAS_NEXITY_DEPS, reason="nexity extra not installed")
async def test_login_propagates_non_auth_client_error(self):
"""Propagate non-auth Cognito errors to preserve failure context."""
server_config = ServerConfig(
Expand Down
12 changes: 7 additions & 5 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading