Skip to content

Commit 8eb08cf

Browse files
authored
Apply feedback to v2 branch (#1971)
Apply feedback form @tetienne in #1872. Feedback on models.py skipped for now, as this will require a larger refactor (like https://github.com/iMicknl/python-overkiz-api/pulls).
1 parent 8c9d3fc commit 8eb08cf

9 files changed

Lines changed: 174 additions & 95 deletions

File tree

pyoverkiz/action_queue.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,15 @@ async def add(
120120
into a single action to respect the gateway limitation of one action per
121121
device in each action group.
122122
123-
:param actions: Actions to queue
124-
:param mode: Command mode (will flush if different from pending mode)
125-
:param label: Label for the action group
126-
:return: QueuedExecution that resolves to exec_id when batch executes
123+
Args:
124+
actions: Actions to queue.
125+
mode: Command mode, which triggers a flush if it differs from the
126+
pending mode.
127+
label: Label for the action group.
128+
129+
Returns:
130+
A `QueuedExecution` that resolves to the `exec_id` when the batch
131+
executes.
127132
"""
128133
batches_to_execute: list[
129134
tuple[list[Action], CommandMode | None, str | None, list[QueuedExecution]]

pyoverkiz/auth/strategies.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from aiohttp import ClientSession, FormData
1616
from botocore.client import BaseClient
1717
from botocore.config import Config
18+
from botocore.exceptions import ClientError
1819
from warrant_lite import WarrantLite
1920

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

215-
def __init__(
216-
self,
217-
credentials: UsernamePasswordCredentials,
218-
session: ClientSession,
219-
server: ServerConfig,
220-
ssl_context: ssl.SSLContext | bool,
221-
api_type: APIType,
222-
) -> None:
223-
"""Initialize CozytouchAuthStrategy with given parameters."""
224-
super().__init__(credentials, session, server, ssl_context, api_type)
225-
226216
async def login(self) -> None:
227217
"""Perform login using Cozytouch username and password."""
228218
form = FormData(
@@ -265,20 +255,9 @@ async def login(self) -> None:
265255
class NexityAuthStrategy(SessionLoginStrategy):
266256
"""Authentication strategy using Nexity session-based login."""
267257

268-
def __init__(
269-
self,
270-
credentials: UsernamePasswordCredentials,
271-
session: ClientSession,
272-
server: ServerConfig,
273-
ssl_context: ssl.SSLContext | bool,
274-
api_type: APIType,
275-
) -> None:
276-
"""Initialize NexityAuthStrategy with given parameters."""
277-
super().__init__(credentials, session, server, ssl_context, api_type)
278-
279258
async def login(self) -> None:
280259
"""Perform login using Nexity username and password."""
281-
loop = asyncio.get_event_loop()
260+
loop = asyncio.get_running_loop()
282261

283262
def _client() -> BaseClient:
284263
return boto3.client(
@@ -296,8 +275,11 @@ def _client() -> BaseClient:
296275

297276
try:
298277
tokens = await loop.run_in_executor(None, aws.authenticate_user)
299-
except Exception as error:
300-
raise NexityBadCredentialsException() from error
278+
except ClientError as error:
279+
code = error.response.get("Error", {}).get("Code")
280+
if code in {"NotAuthorizedException", "UserNotFoundException"}:
281+
raise NexityBadCredentialsException() from error
282+
raise
301283

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

0 commit comments

Comments
 (0)