core: Linkplay error with Audio Pro

The problem

The Linkplay integration seems to recognize my Audio Pro speakers (Models A10 MkII, A15, A28, & C10) and automatically attempts to connect with them, but is unable to due to errors.

I tried to interface directly with the API on my speakers by running curl -v “https://10.0.0.91/httpapi.asp?command=getPlayerStatusEx” in a terminal but the connection simply fails. It’s possible they might be using some different API? They are listed on Linkplay’s site as being powered by Linkplay.

My speakers respond to pings and are able to stream audio fine via Chromecast/Airplay so their network connectivity doesn’t seem to be an issue.

What version of Home Assistant Core has the issue?

2024.9.1

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

Linkplay

Link to integration documentation on our website

https://www.home-assistant.io/integrations/linkplay/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.linkplay.config_flow
Source: components/linkplay/config_flow.py:38
integration: linkplay (documentation, issues)
First occurred: 4:01:24 PM (203 occurrences)
Last logged: 8:52:09 PM

    Failed to connect to LinkPlay device at 10.0.0.94
    Failed to connect to LinkPlay device at 10.0.0.91
    Failed to connect to LinkPlay device at 10.0.0.90
    Failed to connect to LinkPlay device at 10.0.0.93

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1073, in _wrap_create_connection
    sock = await aiohappyeyeballs.start_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohappyeyeballs/impl.py", line 104, in start_connection
    raise first_exception
  File "/usr/local/lib/python3.12/site-packages/aiohappyeyeballs/impl.py", line 81, in start_connection
    sock = await _connect_sock(
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohappyeyeballs/impl.py", line 166, in _connect_sock
    await loop.sock_connect(sock, address)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 641, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 681, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('10.0.0.94', 80)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/linkplay/utils.py", line 48, in session_call_api
    response = await session.get(url)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 657, in _request
    conn = await self._connector.connect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 564, in connect
    proto = await self._create_connection(req, traces, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 975, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1350, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1319, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1088, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 10.0.0.94:80 ssl:default [Connect call failed ('10.0.0.94', 80)]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/linkplay/config_flow.py", line 38, in async_step_zeroconf
    bridge = await linkplay_factory_httpapi_bridge(discovery_info.host, session)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/linkplay/discovery.py", line 60, in linkplay_factory_httpapi_bridge
    return await linkplay_factory_bridge_endpoint(http_endpoint)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/linkplay/discovery.py", line 39, in linkplay_factory_bridge_endpoint
    await bridge.device.update_status()
  File "/usr/local/lib/python3.12/site-packages/linkplay/bridge.py", line 38, in update_status
    self.properties = await self.bridge.json_request(LinkPlayCommand.DEVICE_STATUS)  # type: ignore[assignment]
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/linkplay/bridge.py", line 261, in json_request
    return await self.endpoint.json_request(command)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/linkplay/endpoint.py", line 44, in json_request
    return await session_call_api_json(self._endpoint, self._session, command)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/linkplay/utils.py", line 67, in session_call_api_json
    result = await session_call_api(endpoint, session, command)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/linkplay/utils.py", line 51, in session_call_api
    raise LinkPlayRequestException(
linkplay.exceptions.LinkPlayRequestException: Cannot connect to host 10.0.0.94:80 ssl:default [Connect call failed ('10.0.0.94', 80)] error requesting data from 'http://10.0.0.94/httpapi.asp?command=getStatusEx

Additional information

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 35 (9 by maintainers)

Most upvoted comments

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.

maybe this helps. i obtained it by downloading+unpacking the apk of the wiim app and then decompiling the .dex files with jadx.

Image

edit: as can be seen in the screenshot, there are some functions (G and H) that are used as a general purpose url-factory. searching for the usage of those functions will surface a whole bunch of commands.

if this is of interest to you, let me know. i can provide more (even tho jadx makes this very easy for everyone)

I’ve been looking into the commands to recheck and I think I’ve been too fast. getStatusEx is the device status and getPlayerStatusEx is the player status. It should provide both to be in line with what the protocol documentation mentions. If you can find other methods that provide the current player status, that is what is needed.

You may be right, @silamon. getStatusEx is the only command string I’ve been able to use to get any data at all. It returns “unknown command” for the other handful of commands I’ve tried that I can find in the docs.

Some speculation… The output of getStatusEx mentions a lot of upnp-related data, as if that’s the next thing you’re meant to go to after this call. As an API designer, if the next thing were, say, another httpasp command, I’d at least include an httpaspVersion or something.

I’ll continue trying commands, but at this point I’m not so optimistic.

As I’ve mentioned here, our best bet for getting the complete list of commands would be to find & examine a firmware update belonging to one of the devices without getPlayerStatusEx.

@JonSilver you should probably have a look at the upstream issue, if you haven’t seen it already. It’s the upstream library used in HA.

That is completely new information you’re providing there. Past responses, indicated an invalid json to be returned, not “unknown command”. If that applies to everybody in this thread, then there may be an easy fix to support this.

The certificate is already included. The device you’re having has other issues remaining for this issue to be solved.

I found this post which I translated and was linking to this repo containing the client-certificate needed to talk to the HTTP(s) API on my Audio Pro C5 MkII.

❯ curl -s -k --cert-type pem --cert ~/Downloads/client.pem "https://10.1.20.36:4443/httpapi.asp?command=getStatusEx" | jq
{
  "language": "en_us",
  "firmware": "audiopro_c5-user 1.56 1.56 1.56.503665 test-keys",
  "cast_ver": "1.56. 310669\n",
  "build": "user",
  "project": "ADDON C5 MkII Speaker",
...

@Velleman Can this be used to add support for these devices? 😃

This still does not work in the latest version

AudioPro devices - at least the C3 - don’t use https, and that is exactly the issue: the integration tries to communicate with them using https on port 443 (not 4443), whereas they just speak http on port 80. Here’s the error I get in the log:

  File "/usr/local/lib/python3.12/site-packages/linkplay/utils.py", line 49, in session_call_api
    raise LinkPlayRequestException(
linkplay.exceptions.LinkPlayRequestException:  error requesting data from 'https://192.168.1.173/httpapi.asp?command=getPlayerStatusEx'

If I open the above URL in my browser, I get a “ERR_BAD_SSL_CLIENT_AUTH_CERT” error. If I hit the same URL via http, I get a valid response.

Basically, the integration should be able to auto-detect which protocol to use for each Linkplay device, as some of them work on http. Missing that, we should be allowed to specify it manually, as in the old nagyrobi integration:

media_player:
    - platform: linkplay
      host: 192.168.1.11
      protocol: https
    ...

This is also the reason why AudioPro devices cannot be joined:

  File "/usr/local/lib/python3.12/site-packages/linkplay/utils.py", line 49, in session_call_api
    raise LinkPlayRequestException(
linkplay.exceptions.LinkPlayRequestException: Cannot connect to host 192.168.1.47:443 ssl:default [Connect call failed ('192.168.1.47', 443)] error requesting data from 'https://192.168.1.47/httpapi.asp?command=ConnectMasterAp:JoinGroupMaster:eth0.0.0.0:wifi0.0.0.0'