Skip to content

Commit f2f72b4

Browse files
committed
Log API mode outcome and logout response
1 parent 76765e8 commit f2f72b4

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ When REST mode is active, high-level helpers like `get_device_info()`, `get_host
141141

142142
If you are not sure which encryption method to use, you can leave it empty or pass `None` and use `get_encryption_method` to determine the encryption method.
143143

144-
`get_encryption_method` will return an `EncryptionMethod` when a match is found. Best would be to use this function only during your initial investigation.
144+
`get_encryption_method` will return an `EncryptionMethod` when a match is found and `EncryptionMethod.NONE` if no method matches or REST mode is configured. Best would be to use this function only during your initial investigation.
145145

146146
This function will throw a `LoginTimeoutException` when no match is found, since this is still a HTTP Time Out. This could caused by the wrong encryption method, but also by trying to connect to an inaccessible host.
147147

sagemcom_api/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from typing import Any
1313
import urllib.parse
1414

15+
import logging
1516
from aiohttp import (
1617
ClientConnectorError,
1718
ClientOSError,
@@ -58,6 +59,8 @@
5859
)
5960
from .models import Device, DeviceInfo, PortMapping
6061

62+
LOGGER = logging.getLogger(__name__)
63+
6164

6265
async def retry_login(invocation: Mapping[str, Any]) -> None:
6366
"""Retry login via backoff if an exception occurs."""
@@ -76,7 +79,7 @@ def __init__(
7679
host: str,
7780
username: str,
7881
password: str,
79-
authentication_method: EncryptionMethod | None = None,
82+
authentication_method: EncryptionMethod,
8083
api_mode: ApiMode | str = ApiMode.AUTO,
8184
session: ClientSession | None = None,
8285
ssl: bool | None = False,
@@ -542,30 +545,37 @@ async def login(self):
542545
"""Login to the router using configured API mode."""
543546
if self.api_mode == ApiMode.REST:
544547
self._active_api_mode = ApiMode.REST
548+
LOGGER.info("API mode forced to REST")
545549
return await self.__rest_login()
546550

547551
if self.api_mode == ApiMode.LEGACY:
548552
self._active_api_mode = ApiMode.LEGACY
553+
LOGGER.info("API mode forced to LEGACY")
549554
return await self.__legacy_login()
550555

551556
# Auto-detect mode: try legacy first, then fall back to REST for newer firmwares.
552557
try:
553558
self._active_api_mode = ApiMode.LEGACY
554-
return await self.__legacy_login()
559+
result = await self.__legacy_login()
560+
LOGGER.info("API mode auto-detected as LEGACY")
561+
return result
555562
except Exception as exception: # pylint: disable=broad-except
556563
if not self.__should_fallback_to_rest(exception):
557564
raise
558565

559566
self._active_api_mode = ApiMode.REST
567+
LOGGER.info("API mode auto-detected as REST")
560568
return await self.__rest_login()
561569

562570
async def logout(self):
563571
"""Log out of the Sagemcom F@st device."""
564572
if self._active_api_mode == ApiMode.REST:
565-
await self.__rest_request("POST", "/api/v1/logout")
573+
response = await self.__rest_request("POST", "/api/v1/logout", data={"_": ""})
574+
LOGGER.info("REST logout response: %s", response)
566575
else:
567576
actions = {"id": 0, "method": "logOut"}
568-
await self.__api_request_async([actions], False)
577+
response = await self.__api_request_async([actions], False)
578+
LOGGER.info("JSON-REQ logout response: %s", response)
569579

570580
self._session_id = -1
571581
self._server_nonce = ""

0 commit comments

Comments
 (0)