iMicknl / python-sagemcom-api

(Unofficial) Python wrapper to interact with SagemCom F@st routers via internal API's.
MIT License
89 stars 37 forks source link

JSON structure unexpected by the API - Device/DeviceInfo #129

Closed M4D1NG3R closed 2 years ago

M4D1NG3R commented 2 years ago

Model information

Key Value
Model name Speedport Pro
Hardware Version 03
Software Version 120133.4.5.033.4

Describe the bug

The JSON returned by "Device/DeviceInfo" has a structure unexpected by the API:

{'device_info': {'device_category': '', 'manufacturer': 'DT', ...}}

Therefore, the formatting (DeviceInfo(**data)) returns 'none' for each attribute

with version 1.0.6 the error is not occurring This is currently also breaking the Home Assistant custom component

workaround for Home Assistant OS useres:

  1. download sagemcom_api from GitHub
  2. make changes as seen below / in the PR
  3. copy sagemcom_api folder to config\deps\lib\pythonX.X
  4. edit custom_components/sagemcom_fast/manifest.json from "requirements": [ "sagemcom_api===1.0.7" ], to "requirements": [],

If you run into any problem just comment.

To Reproduce

Steps to reproduce the behavior:

using device_info = await client.get_device_info()

Screenshots

image

image

Additional context

a workaround is to replace in client.py:

...
try:
    data = await self.get_value_by_xpath("Device/DeviceInfo")       
except UnknownPathException:
...

with

...
try:
    data = await self.get_value_by_xpath("Device/DeviceInfo")
    return DeviceInfo(**data.get("device_info"))
except UnknownPathException:
...

[bug]

M4D1NG3R commented 2 years ago

@iMicknl do you need anything else from my side?