Skip to content

Commit

Permalink
Improve code sample
Browse files Browse the repository at this point in the history
  • Loading branch information
iMicknl committed Jan 7, 2024
1 parent a55f0df commit 0815a59
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,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 @@ -79,8 +80,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

0 comments on commit 0815a59

Please sign in to comment.