From b4889d3ddd56c890172309dbbea55e34c610db8e Mon Sep 17 00:00:00 2001 From: Mick Date: Fri, 9 Aug 2024 22:06:56 +0000 Subject: [PATCH] Don't retry on all calls --- sagemcom_api/client.py | 88 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 11 deletions(-) diff --git a/sagemcom_api/client.py b/sagemcom_api/client.py index 2d12263..39b7221 100644 --- a/sagemcom_api/client.py +++ b/sagemcom_api/client.py @@ -257,17 +257,6 @@ async def __post(self, url, data): return result - @backoff.on_exception( - backoff.expo, - ( - AuthenticationException, - LoginRetryErrorException, - LoginTimeoutException, - InvalidSessionException, - ), - max_tries=2, - on_backoff=retry_login, - ) async def __api_request_async(self, actions, priority=False): """Build request to the internal JSON-req API.""" self.__generate_request_id() @@ -376,6 +365,17 @@ async def get_encryption_method(self): return None + @backoff.on_exception( + backoff.expo, + ( + AuthenticationException, + LoginRetryErrorException, + LoginTimeoutException, + InvalidSessionException, + ), + max_tries=1, + on_backoff=retry_login, + ) async def get_value_by_xpath(self, xpath: str, options: dict | None = None) -> dict: """ Retrieve raw value from router using XPath. @@ -395,6 +395,17 @@ async def get_value_by_xpath(self, xpath: str, options: dict | None = None) -> d return data + @backoff.on_exception( + backoff.expo, + ( + AuthenticationException, + LoginRetryErrorException, + LoginTimeoutException, + InvalidSessionException, + ), + max_tries=1, + on_backoff=retry_login, + ) async def get_values_by_xpaths(self, xpaths, options: dict | None = None) -> dict: """ Retrieve raw values from router using XPath. @@ -418,6 +429,17 @@ async def get_values_by_xpaths(self, xpaths, options: dict | None = None) -> dic return data + @backoff.on_exception( + backoff.expo, + ( + AuthenticationException, + LoginRetryErrorException, + LoginTimeoutException, + InvalidSessionException, + ), + max_tries=1, + on_backoff=retry_login, + ) async def set_value_by_xpath( self, xpath: str, value: str, options: dict | None = None ) -> dict: @@ -440,6 +462,17 @@ async def set_value_by_xpath( return response + @backoff.on_exception( + backoff.expo, + ( + AuthenticationException, + LoginRetryErrorException, + LoginTimeoutException, + InvalidSessionException, + ), + max_tries=1, + on_backoff=retry_login, + ) async def get_device_info(self) -> DeviceInfo: """Retrieve information about Sagemcom F@st device.""" try: @@ -460,6 +493,17 @@ async def get_device_info(self) -> DeviceInfo: return DeviceInfo(**data) + @backoff.on_exception( + backoff.expo, + ( + AuthenticationException, + LoginRetryErrorException, + LoginTimeoutException, + InvalidSessionException, + ), + max_tries=1, + on_backoff=retry_login, + ) async def get_hosts(self, only_active: bool | None = False) -> list[Device]: """Retrieve hosts connected to Sagemcom F@st device.""" data = await self.get_value_by_xpath( @@ -473,6 +517,17 @@ async def get_hosts(self, only_active: bool | None = False) -> list[Device]: return devices + @backoff.on_exception( + backoff.expo, + ( + AuthenticationException, + LoginRetryErrorException, + LoginTimeoutException, + InvalidSessionException, + ), + max_tries=1, + on_backoff=retry_login, + ) async def get_port_mappings(self) -> list[PortMapping]: """Retrieve configured Port Mappings on Sagemcom F@st device.""" data = await self.get_value_by_xpath("Device/NAT/PortMappings") @@ -480,6 +535,17 @@ async def get_port_mappings(self) -> list[PortMapping]: return port_mappings + @backoff.on_exception( + backoff.expo, + ( + AuthenticationException, + LoginRetryErrorException, + LoginTimeoutException, + InvalidSessionException, + ), + max_tries=1, + on_backoff=retry_login, + ) async def reboot(self): """Reboot Sagemcom F@st device.""" action = {