Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The Sagemcom F@st series is used by multiple cable companies, where some cable c
| --------------------- | -------------------- | --------------------- | ----------------------------- |
| Sagemcom F@st 3864 | Optus | sha512 | username: guest, password: "" |
| Sagemcom F@st 3865b | Proximus (b-box3) | md5 | |
| Sagemcom F@st 3890V3 | Delta / Zeelandnet | md5 | |
| Sagemcom F@st 3890V3 | Delta / Zeelandnet | sha512 | |
| Sagemcom F@st 3896 | | sha512 | username: admin |
| Sagemcom F@st 4360Air | KPN | md5 | |
| Sagemcom F@st 4353 | Belong Gateway | md5 | username: admin, password: "" |
Expand Down Expand Up @@ -50,13 +50,14 @@ The following script can be used as a quickstart.

```python
import asyncio
from sagemcom_api.enums import EncryptionMethod
from sagemcom_api.client import SagemcomClient
from sagemcom_api.enums import EncryptionMethod
from sagemcom_api.exceptions import NonWritableParameterException

HOST = ""
USERNAME = ""
PASSWORD = ""
ENCRYPTION_METHOD = EncryptionMethod.MD5 # or EncryptionMethod.SHA512
ENCRYPTION_METHOD = EncryptionMethod.SHA512 # or EncryptionMethod.MD5

async def main() -> None:
async with SagemcomClient(HOST, USERNAME, PASSWORD, ENCRYPTION_METHOD) as client:
Expand All @@ -81,8 +82,13 @@ async def main() -> None:
custom_command_output = await client.get_value_by_xpath("Device/UserInterface/AdvancedMode")
print(custom_command_output)

# Set value via XPath notation
custom_command_output = await client.set_value_by_xpath("Device/UserInterface/AdvancedMode", "true")
# Set value via XPath notation and catch specific errors
try:
custom_command_output = await client.set_value_by_xpath("Device/UserInterface/AdvancedMode", "true")
except NonWritableParameterException as exception: # pylint: disable=broad-except
print("Not allowed to set AdvancedMode parameter on your device.")
return

print(custom_command_output)

asyncio.run(main())
Expand Down
7 changes: 4 additions & 3 deletions sagemcom_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ async def __api_request_async(self, actions, priority=False):
}
}

async with self.session.post(
api_host, data="req=" + json.dumps(payload, separators=(",", ":"))
) as response:
form_data = {"req": json.dumps(payload, separators=(",", ":"))}

async with self.session.post(api_host, data=form_data) as response:
if response.status == 400:
result = await response.text()
raise BadRequestException(result)
Expand Down Expand Up @@ -245,6 +245,7 @@ async def __api_request_async(self, actions, priority=False):
async def login(self):
"""TODO."""
actions = {
"id": 0,
"method": "logIn",
"parameters": {
"user": self.username,
Expand Down