33from __future__ import annotations
44
55import asyncio
6- from collections .abc import Mapping
76import hashlib
87import json
98import math
109import random
10+ import urllib .parse
11+ from collections .abc import Mapping
1112from types import TracebackType
1213from typing import Any
13- import urllib .parse
1414
15+ import backoff
16+ import humps
1517from aiohttp import (
1618 ClientConnectorError ,
1719 ClientOSError ,
2022 ServerDisconnectedError ,
2123 TCPConnector ,
2224)
23- import backoff
24- import humps
2525
2626from .const import (
2727 API_ENDPOINT ,
@@ -106,9 +106,7 @@ def __init__(
106106 else ClientSession (
107107 headers = {"User-Agent" : f"{ DEFAULT_USER_AGENT } " },
108108 timeout = ClientTimeout (DEFAULT_TIMEOUT ),
109- connector = TCPConnector (
110- verify_ssl = verify_ssl if verify_ssl is not None else True
111- ),
109+ connector = TCPConnector (verify_ssl = verify_ssl if verify_ssl is not None else True ),
112110 )
113111 )
114112
@@ -143,11 +141,7 @@ def __generate_md5_nonce_hash(self):
143141 def md5 (input_string ):
144142 return hashlib .md5 (input_string .encode ()).hexdigest ()
145143
146- n = (
147- self .__generate_nonce (UINT_MAX )
148- if self ._current_nonce is None
149- else self ._current_nonce
150- )
144+ n = self .__generate_nonce (UINT_MAX ) if self ._current_nonce is None else self ._current_nonce
151145 f = 0
152146 l_nonce = ""
153147 ha1 = md5 (self .username + ":" + l_nonce + ":" + md5 (self .password ))
@@ -173,9 +167,7 @@ def __generate_hash(self, value, authentication_method=None):
173167
174168 def __get_credential_hash (self ):
175169 """Build credential hash."""
176- return self .__generate_hash (
177- self .username + ":" + self ._server_nonce + ":" + self ._password_hash
178- )
170+ return self .__generate_hash (self .username + ":" + self ._server_nonce + ":" + self ._password_hash )
179171
180172 def __generate_auth_key (self ):
181173 """Build auth key."""
@@ -240,8 +232,7 @@ async def __post(self, url, data):
240232
241233 # No errors
242234 if (
243- error ["description" ] == XMO_REQUEST_NO_ERR
244- or error ["description" ] == "Ok" # NOQA: W503
235+ error ["description" ] == XMO_REQUEST_NO_ERR or error ["description" ] == "Ok" # NOQA: W503
245236 ):
246237 return result
247238
@@ -373,9 +364,7 @@ async def get_encryption_method(self):
373364 for encryption_method in EncryptionMethod :
374365 try :
375366 self .authentication_method = encryption_method
376- self ._password_hash = self .__generate_hash (
377- self .password , encryption_method
378- )
367+ self ._password_hash = self .__generate_hash (self .password , encryption_method )
379368
380369 await self .login ()
381370
@@ -468,9 +457,7 @@ async def get_values_by_xpaths(self, xpaths, options: dict | None = None) -> dic
468457 max_tries = 1 ,
469458 on_backoff = retry_login ,
470459 )
471- async def set_value_by_xpath (
472- self , xpath : str , value : str , options : dict | None = None
473- ) -> dict :
460+ async def set_value_by_xpath (self , xpath : str , value : str , options : dict | None = None ) -> dict :
474461 """
475462 Retrieve raw value from router using XPath.
476463
@@ -534,9 +521,7 @@ async def get_device_info(self) -> DeviceInfo:
534521 )
535522 async def get_hosts (self , only_active : bool | None = False ) -> list [Device ]:
536523 """Retrieve hosts connected to Sagemcom F@st device."""
537- data = await self .get_value_by_xpath (
538- "Device/Hosts/Hosts" , options = {"capability-flags" : {"interface" : True }}
539- )
524+ data = await self .get_value_by_xpath ("Device/Hosts/Hosts" , options = {"capability-flags" : {"interface" : True }})
540525 devices = [Device (** d ) for d in data ]
541526
542527 if only_active :
0 commit comments