Skip to content

Commit f1fbae7

Browse files
committed
Probe REST when auto detecting encryption
1 parent 6698f42 commit f1fbae7

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

sagemcom_api/client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,25 @@ async def __rest_login(self):
417417
)
418418
return True
419419

420+
async def __probe_rest_availability(self) -> bool:
421+
"""Try a REST login/logout sequence to detect REST-only firmware."""
422+
try:
423+
await self.__rest_request(
424+
"POST",
425+
"/api/v1/login",
426+
data={"login": self.username, "password": self.password},
427+
)
428+
except (
429+
AuthenticationException,
430+
UnauthorizedException,
431+
UnsupportedHostException,
432+
UnknownException,
433+
):
434+
return False
435+
436+
await self.__rest_request("POST", "/api/v1/logout", data={"_": ""})
437+
return True
438+
420439
@staticmethod
421440
def __first_value(data: dict[str, Any], *keys: str) -> Any:
422441
"""Return the first non-None value from data for the given keys."""
@@ -585,6 +604,9 @@ async def get_encryption_method(self) -> EncryptionMethod:
585604
if self.api_mode == ApiMode.REST:
586605
return EncryptionMethod.NONE
587606

607+
if self.api_mode == ApiMode.AUTO and await self.__probe_rest_availability():
608+
return EncryptionMethod.NONE
609+
588610
for encryption_method in EncryptionMethod:
589611
try:
590612
if encryption_method == EncryptionMethod.NONE:

0 commit comments

Comments
 (0)