Skip to content

Conversation

@rhegner
Copy link
Contributor

@rhegner rhegner commented May 11, 2025

I had a second problem with my "Sunrise Internet Box".

Attempting to read the value of the following xpath failed:

Device/IP/Interfaces/Interface[Alias='IP_DATA']/IPv4Addresses/IPv4Address[Alias='IP_DATA_ADDRESS']/IPAddress

Instead of the IP address I was looking for, get_value_by_xpath returned a JSON structure with lots of status information in it, but not the IP address I was looking for. Turns out that url quoting messed things up.

So I added a new parameter to the get_value_by_xpath function:

The following now returns the desired IP address as expected:

await client.get_value_by_xpath("Device/IP/Interfaces/Interface[Alias='IP_DATA']/IPv4Addresses/IPv4Address[Alias='IP_DATA_ADDRESS']/IPAddress", { "capability-flags": { "interface": True }}, False)

@rhegner rhegner requested a review from iMicknl as a code owner May 11, 2025 20:37
@rhegner
Copy link
Contributor Author

rhegner commented May 11, 2025

PS: Depending on what the original intent was for using that url quoting, a more elegant approach could be to specify the required characters as "safe characters" (instead of introducing a new parameter).

The following works fine for me too:

        actions = {
            "id": 0,
            "method": "getValue",
            "xpath": urllib.parse.quote(xpath, "/=[]'"),
            "options": options if options else {},
        }

https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote

@iMicknl
Copy link
Owner

iMicknl commented May 11, 2025

@rhegner I would prefer your second option, to not add additional parameters here :)

@rhegner
Copy link
Contributor Author

rhegner commented May 12, 2025

Yes, it's cleaner. I updated my PR.

Copy link
Owner

@iMicknl iMicknl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@iMicknl iMicknl merged commit 35bc37d into iMicknl:main May 12, 2025
4 checks passed
@rhegner
Copy link
Contributor Author

rhegner commented May 25, 2025

@iMicknl do you plan to release a new version of your library with this PR included anytime soon?

@iMicknl
Copy link
Owner

iMicknl commented May 25, 2025

@iMicknl do you plan to release a new version of your library with this PR included anytime soon?

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants