home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.76k stars 30k forks source link

Hegel amp DMR "not available" after fw upgrade - UpnpXmlParseError #67788

Closed mrcrutch closed 2 years ago

mrcrutch commented 2 years ago

The problem

Hi guys! Yesterday I upgraded my amp firmware to a recently version (Hegel H190 - was at 5107.29, upgraded to 5117.31)

DMR integration is no more working on HA (amp is shown as "unavailable") I tried to delete and re-configure the DMR integration but this didn't fix the problem. The weird thing is, other dmr apps (such as BubbleUpnp) are still working correcly.

Looking at log, I can find: Failed connecting to recently alive device at http://<my-amp-ip>:38400/description.xml: UpnpXmlParseError('no element found: line 1, column 0')

Comparing the two decription.xml versions (the one that came with the old firmware with the new one), they are exactly the same.

What I noticed, is that the new firmware comes with an empty QPlay.xml. The old one was a 6K file containing some xml tags... This could be a part of the problem, but I wonder why other apps are still working.

Looking inside description.xml, I can see that QPlay is mentioned in <SCPDURL>/QPlay.xml</SCPDURL>

What could we do to further investigate the problem? If needed I can provide tcpdump captures, and I'm also in touch with Hegel support by mail.

What version of Home Assistant Core has the issue?

2022.3.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

DMR - DLNA Digital Media Renderer

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

Install is an HA Core install inside Python venv.

probot-home-assistant[bot] commented 2 years ago

dlna_dmr documentation dlna_dmr source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @stevenlooman, @chishm, mind taking a look at this issue as it has been labeled with an integration (dlna_dmr) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

chishm commented 2 years ago

Thank you for the bug report. As you've found, it looks like your amp has missing XML content for the QPlay service descriptor. There's already been one hack to async_upnp_client to deal with wrong XML, so it may be possible to add some more hacks in.

However, I'd prefer not to have to hack around a non-working device. Are you able to contact the device manufacturer to file a bug report with them?

mrcrutch commented 2 years ago

Many thanks @chishm for your quick reply. Yes, Hegel has an excellent mail support, they usually answer quickly so I can sure get in touch with them to notify the issue. My question is, do you think I can pretty sure refer the issue to the empty QPlay.xml? As far as you know, is there any way to test if the old version of QPlay.xml (which I have saved) would also work with the new firmware eg by tricking a local description.xml and QPlay.xml published in www folder and adding them as a "fake dmr"? (pls be sorry for my poor english...)

chishm commented 2 years ago

It might be possible to test async_upnp_client if you have copies of all of the XML files, and can replicate the directory layout of the amp's file server. It looks like all the XML files sit in the same place, so that should be easy.

Start by installing async_upnp_client in a virtual environment and run ipython:

python3 -m venv /tmp/upnp
source /tmp/upnp/bin/activate
pip install async-upnp-client ipython
ipython

In another window, set up a simple HTTP server:

cd <path/to/www/folder>
python3 -m http.server --bind localhost

Back in the first window, use async_upnp_client to try to read the files:

import aiohttp
from async_upnp_client.aiohttp import AiohttpSessionRequester
from async_upnp_client import UpnpFactory

client = aiohttp.ClientSession()
requester = AiohttpSessionRequester(client, with_sleep=True)
upnp_factory = UpnpFactory(requester, non_strict=True)
device = await upnp_factory.async_create_device("http://localhost/description.xml")
print(device.services)

If everything is ok, this should not raise any exceptions. If you want to, you could also set non_strict=False in the upnp_factory = UpnpFactory(requester, non_strict=False) line, to validate the XML is completely correct.

This won't let you connect to the amp itself, but it will tell you if the descriptors are correct.

mrcrutch commented 2 years ago

Hi @chishm, many thanks for your response.

I'm not a professional in python programming, but, that said..

I managed to get it working by applying the attached small patch to client_factory.py in async_upnp_client package. . client_factory.patch.txt

I would ask if someone could review this before sending a pull request.

As far as I could understand, the problem raise when a service refers to a SCPDurl where GET request actually downloads an empty file. (In this case, description string and thus scpd_el variable, coudn't be retrieved.

Hope this could be the right way. In my case this solved my problem.

I'm also in touch with Hegel, to also fix the empty file in the amp firmware.

mrcrutch commented 2 years ago

In the meantime I tried to open a pull request in async_upnp_client. https://github.com/StevenLooman/async_upnp_client/pull/127

It's my first pull request for others people's projects... Hope I've done a not too bad job :) So maybe this issue can be closed since it's not closely related to HA?

chishm commented 2 years ago

If you don't mind, I'll make some suggestions on that PR.

Also, you can put a link to this issue in that PR's description for GitHub to automatically link this issue back to there. Sometimes it even auto-closes the issue when the PR is merged.

mrcrutch commented 2 years ago

Many thanks @chishm, would be great if you could suggest improvements to my PR! We'll keep up to date!

chishm commented 2 years ago

I'm glad to help with your first PR. With some more practice you'll be a Python-pro, writing your own integrations for Home Assistant!

mrcrutch commented 2 years ago

An update: Christian, from Hegel, just confirmed me that the issue has been passed to their development team for further investigation. So might be that it will be solved also at amp side.

mrcrutch commented 2 years ago

Just as a notice, @StevenLooman just merged our patch pr and opened a pr in HomeAssistant to upgrade async_upnp_version which has also been merged (https://github.com/home-assistant/core/pull/68310). So this issue should hopefully be resolved in the next 2022.4 version. If it's allowed I'll keep this open just for some days to give updates if we'll have news from the Hegel side about firmware fixing.

github-actions[bot] commented 2 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.