Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 77 additions & 11 deletions sagemcom_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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(
Expand All @@ -473,13 +517,35 @@ 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")
port_mappings = [PortMapping(**p) for p in data]

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 = {
Expand Down