Skip to content

Commit 76765e8

Browse files
committed
Expose EncryptionMethod.NONE results
1 parent 70e45d2 commit 76765e8

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

sagemcom_api/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,15 @@ def __ensure_legacy_api(self):
579579
"Use helper methods supported for REST firmware instead."
580580
)
581581

582-
async def get_encryption_method(self):
582+
async def get_encryption_method(self) -> EncryptionMethod:
583583
"""Determine which encryption method to use for authentication and set it directly."""
584584
if self.api_mode == ApiMode.REST:
585-
return None
585+
return EncryptionMethod.NONE
586586

587587
for encryption_method in EncryptionMethod:
588588
try:
589+
if encryption_method == EncryptionMethod.NONE:
590+
continue
589591
self.authentication_method = encryption_method
590592
self._password_hash = self.__generate_hash(
591593
self.password, encryption_method
@@ -605,7 +607,7 @@ async def get_encryption_method(self):
605607
):
606608
pass
607609

608-
return None
610+
return EncryptionMethod.NONE
609611

610612
@backoff.on_exception(
611613
backoff.expo,

sagemcom_api/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class EncryptionMethod(StrEnum):
1818
MD5 = "MD5"
1919
MD5_NONCE = "MD5_NONCE"
2020
SHA512 = "SHA512"
21+
NONE = "NONE"
2122

2223

2324
@unique

tests/unit/test_client_basic.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ async def test_login_auto_fallbacks_to_rest_when_legacy_503():
187187
assert mock_session.request.call_count == 1
188188

189189

190+
@pytest.mark.asyncio
191+
async def test_get_encryption_method_rest_returns_none():
192+
"""REST mode should immediately signal that no encryption method is needed."""
193+
client = SagemcomClient(
194+
host="192.168.1.1",
195+
username="admin",
196+
password="admin",
197+
api_mode=ApiMode.REST,
198+
)
199+
200+
result = await client.get_encryption_method()
201+
202+
assert result == EncryptionMethod.NONE
203+
await client.close()
204+
205+
190206
@pytest.mark.asyncio
191207
async def test_get_hosts_rest_mode():
192208
"""get_hosts should parse wifi and ethernet devices on REST firmware."""

0 commit comments

Comments
 (0)