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
73.65k stars 30.79k forks source link

frontier_silicon: "Unknown error" when connecting to Pure Connect+ DAB #94081

Closed philpem closed 1 year ago

philpem commented 1 year ago

The problem

I tried to connect Home Assistant to my new Pure Connect+ DAB/FM/Internet radio. It wasn't auto-detected by Home Assistant, so I added it manually.

When I did so, I entered its IP address in "Host", and got the error message "Unknown error".

The only thing relevant in the logs is:

Logger: homeassistant.components.frontier_silicon.config_flow
Source: components/frontier_silicon/config_flow.py:105
Integration: Frontier Silicon ([documentation](https://www.home-assistant.io/integrations/frontier_silicon), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+frontier_silicon%22))
First occurred: 17:48:09 (4 occurrences)
Last logged: 17:49:57
syntax error: line 1, column 0

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/frontier_silicon/config_flow.py", line 105, in async_step_user
    self._webfsapi_url = await AFSAPI.get_webfsapi_endpoint(device_url)
  File "/usr/local/lib/python3.10/site-packages/afsapi/api.py", line 133, in get_webfsapi_endpoint
    doc = ET.fromstring(await resp.text(encoding="utf-8"))
  File "/usr/local/lib/python3.10/xml/etree/ElementTree.py", line 1342, in XML
    parser.feed(text)
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0

If I connect to one of the FSAPI endpoints manually with a web browser, e.g. http://10.0.0.226/device , I get a "netRemote" XML response. /fsapi/GET/netRemote.sys.info.radioId?pin=1234 returns a fsapiResponse response, with FS_OK status and the radio's unique ID in the response.

What version of Home Assistant Core has the issue?

core-2023.5.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Frontier Silicon

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

No response

home-assistant[bot] commented 1 year ago

Hey there @wlcrs, mind taking a look at this issue as it has been labeled with an integration (frontier_silicon) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `frontier_silicon` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign frontier_silicon` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


frontier_silicon documentation frontier_silicon source (message by IssueLinks)

wlcrs commented 1 year ago

What is the exact output of your http://10.0.0.226/device ?

Mine looks like this:

<netRemote>
<friendlyName>Keukenradio</friendlyName>
<version>ir-mmi-FS2026-0500-0515-Stream94i_V2.14.35c.EX86167-V1.04</version>
<webfsapi>http://192.168.1.183:80/fsapi</webfsapi>
</netRemote>
philpem commented 1 year ago

Via curl http://10.0.0.226/device:

<netRemote>
<friendlyName>frname</friendlyName>
<version>ir-cui-FS2340-0000-0165_V4.5.13.707296-1A17</version>
<webfsapi>http://10.0.0.226:80/fsapi</webfsapi>
</netRemote>
wlcrs commented 1 year ago

Can you run curl again with -vvv? Maybe the headers give a clue about the root cause. Is it an encoding problem?

philpem commented 1 year ago
$ curl -vvv http://10.0.0.226/device
*   Trying 10.0.0.226:80...
* Connected to 10.0.0.226 (10.0.0.226) port 80 (#0)
> GET /device HTTP/1.1
> Host: 10.0.0.226
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/xml
< Access-Control-Allow-Origin: *
< Content-Length: 172
< 
<netRemote>
<friendlyName>frname</friendlyName>
<version>ir-cui-FS2340-0000-0165_V4.5.13.707296-1A17</version>
<webfsapi>http://10.0.0.226:80/fsapi</webfsapi>
</netRemote>
* Closing connection 0
wlcrs commented 1 year ago

That sadly does not help me a lot.

I created the smallest possible piece of code to help me debug further:

Can you please run pip3 install aiohttp, and then execute the following file:

import xml.etree.ElementTree as ET
import asyncio
import aiohttp

async def test_read():
  async with aiohttp.ClientSession() as client:
    resp = await client.get("http://10.0.0.226/device")
    doc = ET.fromstring(await resp.text(encoding="utf-8"))

    print(doc)

    api = doc.find("webfsapi")

    print(api)
    print(api.text)

asyncio.run(test_read(), debug=True)

What does it output? If you are getting an error: does it go away if you change the encoding from "utf-8" to "ascii" ?

philpem commented 1 year ago

This is on my desktop PC as I'm not sure how to run the script under HASS OS:

$ python3 test.py 
<Element 'netRemote' at 0x7fa94c108cc0>
<Element 'webfsapi' at 0x7fa94c108db0>
http://10.0.0.226:80/fsapi

The output is the same with both ASCII and UTF-8 encoding.

I've also tried running CURL from the HASS terminal, and got the same result as on my desktop (same XML).

eSoCGN commented 1 year ago

Hi.

I second this. My device is a "Blaupunkt-Napoli-DAB" and internet radio. And unfortunally not reachable via Homeassistant any more. Versions of HA:

curl http:///device

<netRemote>
<friendlyName>frname</friendlyName>
<version>ir-cui-FS2340-0000-0061_V4.5.6.9526d3-2A2</version>
<webfsapi>http://<ip>:80/fsapi</webfsapi>
</netRemote>

curl -vvv http://:80/device

*   Trying <ip>:80...
* Connected to <ip> (<ip>) port 80 (#0)
> GET /device HTTP/1.1
> Host: <ip>
> User-Agent: curl/7.74.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/xml
< Access-Control-Allow-Origin: *
< Content-Length: 170
<
<netRemote>
<friendlyName>frname</friendlyName>
<version>ir-cui-FS2340-0000-0061_V4.5.6.9526d3-2A2</version>
<webfsapi>http://<ip>:80/fsapi</webfsapi>
</netRemote>

python3 test.py

<Element 'netRemote' at 0x7f2e47270590>
<Element 'webfsapi' at 0x7f2e472705e0>
http://<ip>:80/fsapi

If I can check anything else to help and get this up and running again let me know. I loved this plugin very much.

Thank you and kind regards Eric

issue-triage-workflows[bot] commented 1 year 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.

philpem commented 1 year ago

Tested on the latest Home Assistant and it seems to be fixed, replaced with #97807, which is having no entities discovered for the radio... further discussion on there...