Skip to content
Merged
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
13 changes: 9 additions & 4 deletions pyoverkiz/action_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,15 @@ async def add(
into a single action to respect the gateway limitation of one action per
device in each action group.

:param actions: Actions to queue
:param mode: Command mode (will flush if different from pending mode)
:param label: Label for the action group
:return: QueuedExecution that resolves to exec_id when batch executes
Args:
actions: Actions to queue.
mode: Command mode, which triggers a flush if it differs from the
pending mode.
label: Label for the action group.

Returns:
A `QueuedExecution` that resolves to the `exec_id` when the batch
executes.
"""
batches_to_execute: list[
tuple[list[Action], CommandMode | None, str | None, list[QueuedExecution]]
Expand Down
32 changes: 7 additions & 25 deletions pyoverkiz/auth/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from aiohttp import ClientSession, FormData
from botocore.client import BaseClient
from botocore.config import Config
from botocore.exceptions import ClientError
from warrant_lite import WarrantLite

from pyoverkiz.auth.base import AuthContext, AuthStrategy
Expand Down Expand Up @@ -212,17 +213,6 @@ async def _request_access_token(
class CozytouchAuthStrategy(SessionLoginStrategy):
"""Authentication strategy using Cozytouch session-based login."""

def __init__(
self,
credentials: UsernamePasswordCredentials,
session: ClientSession,
server: ServerConfig,
ssl_context: ssl.SSLContext | bool,
api_type: APIType,
) -> None:
"""Initialize CozytouchAuthStrategy with given parameters."""
super().__init__(credentials, session, server, ssl_context, api_type)

async def login(self) -> None:
"""Perform login using Cozytouch username and password."""
form = FormData(
Expand Down Expand Up @@ -265,20 +255,9 @@ async def login(self) -> None:
class NexityAuthStrategy(SessionLoginStrategy):
"""Authentication strategy using Nexity session-based login."""

def __init__(
self,
credentials: UsernamePasswordCredentials,
session: ClientSession,
server: ServerConfig,
ssl_context: ssl.SSLContext | bool,
api_type: APIType,
) -> None:
"""Initialize NexityAuthStrategy with given parameters."""
super().__init__(credentials, session, server, ssl_context, api_type)

async def login(self) -> None:
"""Perform login using Nexity username and password."""
loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()

def _client() -> BaseClient:
return boto3.client(
Expand All @@ -296,8 +275,11 @@ def _client() -> BaseClient:

try:
tokens = await loop.run_in_executor(None, aws.authenticate_user)
except Exception as error:
raise NexityBadCredentialsException() from error
except ClientError as error:
code = error.response.get("Error", {}).get("Code")
if code in {"NotAuthorizedException", "UserNotFoundException"}:
raise NexityBadCredentialsException() from error
raise

id_token = tokens["AuthenticationResult"]["IdToken"]

Expand Down
Loading
Loading