StevenLooman / home-assistant-dlna-dmr

DLNA/DMR component for home-assistant
Other
14 stars 1 forks source link

Cannot control DLNA media player #9

Closed stephanfevrier closed 5 years ago

stephanfevrier commented 5 years ago

Hello Steven,

I've been trying to set up my Venz A5 speaker using your component. Everything seems to work, except the controls. I cannot play, pause or change volume through Home Assistant (0.82.1/Hassbian). I would be grateful for your advice.

My configuration.yaml reads

media_player:
  - platform: dlna_dmr
    name: Emilys Speaker
    url: http://192.168.8.135:49152/upnp

I get the error

2018-11-30 20:45:34 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform dlna_dmr Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File "/usr/lib/python3.5/asyncio/tasks.py", line 400, in wait_for return fut.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result raise self._exception
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step result = coro.send(None)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/media_player/dlna_dmr.py", line 142, in async_setup_platform upnp_device = await factory.async_create_device(url) 
File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/__init__.py", line 843, in async_create_device root = await self._async_get_url_xml(description_url)
File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/__init__.py", line 1044, in _async_get_url_xml raise UpnpError() async_upnp_client.UpnpError
2018-11-30 20:45:34 INFO (Thread-14) [homeassistant.components.media_player.spotify] New Devices: {'Emilys Speaker': '81ba5e2a340599ce207b32f6abda463532ed1df8'}
2018-11-30 20:45:36 WARNING (MainThread) [homeassistant.loader] You are using a custom component for climate.evohome which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant. 
2018-11-30 20:45:49 INFO (MainThread) [homeassistant.components.discovery] Found new service: dlna_dmr {'ssdp_description': 'http://192.168.8.135:49152/description.xml', 'upnp_device_type': 'urn:schemas-upnp-org:device:MediaRenderer:1', 'host': '192.168.8.135', 'name': 'Emily', 'serial': '00001', 'udn': 'uuid:FF31F012-4AD3-10B5-A262-4DECFF31F012', 'port': 49152, 'manufacturer': 'wiimu', 'model_name': 'WiiMu LinkPlayer', 'model_number': 'V01-Feb 22 2017'}
2018-11-30 20:45:49 INFO (MainThread) [homeassistant.components.discovery] Unknown service discovered: spotify_connect {'properties': {'CPath': '/goform/spotifyConnect', 'VERSION': '1.0'}, 'port': 5356, 'host': '192.168.8.135', 'hostname': 'VENZ_A5_7608.local.'}
2018-11-30 20:46:01 ERROR (MainThread) [aiohttp.server] Error handling request Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_protocol.py", line 390, in start resp = await self._request_handler(request)
File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/aiohttp.py", line 138, in _handle_request status = await self.event_handler.handle_notify(headers, body)
File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/__init__.py", line 178, in handle_notify service.notify_changed_state_variables(changes)
File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/__init__.py", line 467, in notify_changed_state_variables self.on_event(self, changed_state_variables)
File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/dlna.py", line 170, in _on_event dlna_handle_notify_last_change(state_variable)
File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/dlna.py", line 52, in dlna_handle_notify_last_change el_event = ET.fromstring(state_var.value)
File "/usr/lib/python3.5/xml/etree/ElementTree.py", line 1344, in XML parser.feed(text)
File "<string>", line None xml.etree.ElementTree.ParseError: mismatched tag: line 45, column 2

upnp_info.py returns

    -> Server String: Linux/2.6.36+
    ==== XML Attributes ===
    -> Device Type: urn:schemas-upnp-org:device:MediaRenderer:1
    -> Friendly Name: Emily
    -> Manufacturer: wiimu
    -> Manufacturer URL: http://www.wiimu.com/
    -> Model Description: WiiMu LinkPlayer
    -> Model Name: WiiMu LinkPlayer
    -> Model Number: V01-Feb 22 2017

    -> Services:
        => Service Type: urn:schemas-upnp-org:service:AVTransport:1
        => Control: /upnp/control/rendertransport1
        => Events: /upnp/event/rendertransport1
        => API: http://192.168.8.135:49152/upnp/rendertransportSCPD.xml
            - GetCurrentTransportActions
            - GetDeviceCapabilities
            - GetMediaInfo
            - GetPositionInfo
            - GetTransportInfo
            - GetTransportSettings
            - Next
            - Pause
            - Play
            - Previous
            - Seek
            - SetAVTransportURI
            - Stop
            - GetPlayType
            - GetInfoEx
            - SetPlayMode
        => Service Type: urn:schemas-upnp-org:service:ConnectionManager:1
        => Control: /upnp/control/renderconnmgr1
        => Events: /upnp/event/renderconnmgr1
        => API: http://192.168.8.135:49152/upnp/renderconnmgrSCPD.xml
            - GetCurrentConnectionIDs
            - GetCurrentConnectionInfo
            - GetProtocolInfo
        => Service Type: urn:schemas-upnp-org:service:RenderingControl:1
        => Control: /upnp/control/rendercontrol1
        => Events: /upnp/event/rendercontrol1
        => API: http://192.168.8.135:49152/upnp/rendercontrolSCPD.xml
            - GetMute
            - GetVolume
            - GetChannel
            - GetEqualizer
            - ListPresets
            - SelectPreset
            - SetMute
            - SetVolume
            - SetChannel
            - SetEqualizer
            - GetSimpleDeviceInfo
            - GetControlDeviceInfo
            - MultiPlaySlaveMask
            - SetAlarmQueue
            - GetAlarmQueue
            - DeleteAlarmQueue
            - SetDeviceName
        => Service Type: urn:schemas-wiimu-com:service:PlayQueue:1
        => Control: /upnp/control/PlayQueue1
        => Events: /upnp/event/PlayQueue1
        => API: http://192.168.8.135:49152/upnp/PlayQueueSCPD.xml
            - CreateQueue
            - ReplaceQueue
            - DeleteQueue
            - BackUpQueue
            - AppendQueue
            - BrowseQueue
            - SetQueueLoopMode
            - GetQueueLoopMode
            - SetQueuePolicy
            - PlayQueueWithIndex
            - AppendTracksInQueue
            - RemoveTracksInQueue
            - AppendTracksInQueueEx
            - SetKeyMapping
            - GetKeyMapping
            - GetQueueOnline
            - SearchQueueOnline
            - SetQueueRecord
            - SetSongsRecord
            - UserRegister
            - UserLogin
            - UserLogout
            - GetUserInfo
            - GetUserAccountHistory
            - SetUserFavorites
            - GetUserFavorites
            - GetQueueIndex
            - SetSpotifyPreset
        => Service Type: urn:schemas-tencent-com:service:QPlay:1
        => Control: /upnp/control/QPlay1
        => Events: /upnp/event/QPlay1
        => API: http://192.168.8.135:49152/upnp/QPlaySCPD.xml
            - InsertTracks
            - RemoveTracks
            - RemoveAllTracks
            - GetTracksInfo
            - SetTracksInfo
            - GetTracksCount
            - GetMaxTracks
            - QPlayAuth
            - SetNetwork
StevenLooman commented 5 years ago

Hello Stephan,

Thank you for your report and for providing the additional information. From the logs there are two errors. The first is a generic when reading the XML. To solve this I want to ask you to get these files and put them somewhere online or mail them to me:

These files together provide the description for which services the device provides.

The second error is that your device is sending an update but the software is not properly reading this. Can you add this to your home assistant configuration:

logger:
  default: info
  logs:
    homeassistant.components.media_player.dlna_dmr: debug
    async_upnp_client: debug
    async_upnp_client.discovery: info
    async_upnp_client.dlna: debug
    async_upnp_client.traffic: debug

This will silence home assistant mostly, but report a lot of data about UPnP/DLNA. If the logs become too long to copy/paste here, please put them somewhere online or mail them.

stephanfevrier commented 5 years ago

Hi Steven,

Attached you will find the requested files and logs. Let me know if you would need anything else and thanks in advance for your time and support.

Cheers,

Stephan

StevenLooman commented 5 years ago

Thank you for your reply. Unfortunately, no files are attached to your reply. I think the files weren't added as you responded by mail.

Can you add them again?

stephanfevrier commented 5 years ago

I couldn't attach neither XML nor zipped files, so renamed them to txt.

home-assistant.log QPlaySCPD.txt rendertransportSCPD.txt PlayQueueSCPD.txt renderconnmgrSCPD.txt rendercontrolSCPD.txt description.txt

StevenLooman commented 5 years ago

Thank you for the logs. It helped determining what is wrong.

There are two things wrong:

  1. The URL entered in your config entry (currently http://192.168.8.135:49152/upnp) should be http://192.168.8.135:49152/description.xml;
  2. The Event your device is sending back is invalid XML. I will change async_upnp_client to do more effort to try to parse this later this week.

Please change the URL for you config entry and try again.

StevenLooman commented 5 years ago

Fixed. If all goes well it should be landing in home assistant in a while.

stephanfevrier commented 5 years ago

Interesting. In this case I suggest that, apart from improved parsing, the configuration section of the official installation instructions on https://www.home-assistant.io/components/media_player.dlna_dmr/ should be improved and explain, that URL must point specifically to description.xml.

Nevertheless, my problem does not yet seem to be solved. I still get errors

2018-12-07 20:07:50 DEBUG (MainThread) [async_upnp_client.traffic] Got response:
412
Server: Linux/2.6.36+
Connection: close
Content-Length: 58
Content-Type: text/html

<html><body><h1>412 Precondition Failed</h1></body></html>
2018-12-07 20:07:50 ERROR (MainThread) [async_upnp_client] Did not receive 200, but 412
2018-12-07 20:07:50 DEBUG (MainThread) [async_upnp_client.dlna] Resubscribing to service: <UpnpService(urn:upnp-org:serviceId:AVTransport, uuid:FF31F012-4AD3-10B5-A262-4DECFF31F012)>
2018-12-07 20:07:50 DEBUG (MainThread) [async_upnp_client] Resubscribing to: <UpnpService(urn:upnp-org:serviceId:AVTransport, uuid:FF31F012-4AD3-10B5-A262-4DECFF31F012)>
2018-12-07 20:07:50 DEBUG (MainThread) [async_upnp_client.traffic] Sending request:
SUBSCRIBE http://192.168.8.135:49152/upnp/event/rendertransport1
Host: 192.168.8.135:49152
SID: uuid:b0fd90e6-1dd1-11b2-9c9c-9403c60c7e52
TIMEOUT: Second-0:30:00

2018-12-07 20:07:50 DEBUG (MainThread) [async_upnp_client.traffic] Got response:
412
Server: Linux/2.6.36+
Connection: close
Content-Length: 58
Content-Type: text/html

<html><body><h1>412 Precondition Failed</h1></body></html>
2018-12-07 20:07:50 ERROR (MainThread) [async_upnp_client] Did not receive 200, but 412
2018-12-07 20:08:01 DEBUG (MainThread) [async_upnp_client.traffic] Sending request:
POST http://192.168.8.135:49152/upnp/control/rendertransport1
Host: 192.168.8.135:49152
SOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo"
Content-Length: 399
Content-Type: text/xml
<?xml version="1.0"?>
        <s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
          <s:Body>
            <u:GetTransportInfo xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
                <InstanceID>0</InstanceID>
            </u:GetTransportInfo>
           </s:Body>
        </s:Envelope>

and

2018-12-07 19:53:07 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_protocol.py", line 390, in start
    resp = await self._request_handler(request)
  File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/aiohttp.py", line 138, in _handle_request
    status = await self.event_handler.handle_notify(headers, body)
  File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/__init__.py", line 178, in handle_notify
    service.notify_changed_state_variables(changes)
  File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/__init__.py", line 467, in notify_changed_state_variables
    self.on_event(self, changed_state_variables)
  File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/dlna.py", line 170, in _on_event
    dlna_handle_notify_last_change(state_variable)
  File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/dlna.py", line 52, in dlna_handle_notify_last_change
    el_event = ET.fromstring(state_var.value)
  File "/usr/lib/python3.5/xml/etree/ElementTree.py", line 1344, in XML
    parser.feed(text)
  File "<string>", line None
xml.etree.ElementTree.ParseError: mismatched tag: line 26, column 2
2018-12-07 19:53:10 DEBUG (MainThread) [async_upnp_client.traffic] Sending request:
POST http://192.168.8.135:49152/upnp/control/rendertransport1
Host: 192.168.8.135:49152
SOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo"
Content-Length: 399
Content-Type: text/xml
<?xml version="1.0"?>
        <s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
          <s:Body>
            <u:GetTransportInfo xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
                <InstanceID>0</InstanceID>
            </u:GetTransportInfo>
           </s:Body>
        </s:Envelope>

2018-12-07 19:53:10 DEBUG (MainThread) [async_upnp_client.traffic] Got response:
200
Content-Length: 411
Content-Type: text/xml; charset="utf-8"
Server: Linux/2.6.36+

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body>
<u:GetTransportInfoResponse xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
<CurrentTransportState>STOPPED</CurrentTransportState>
<CurrentTransportStatus>OK</CurrentTransportStatus>
<CurrentSpeed>1</CurrentSpeed>
</u:GetTransportInfoResponse>
</s:Body> </s:Envelope>

Thank you for looking into this again.

StevenLooman commented 5 years ago

Interesting. In this case I suggest that, apart from improved parsing, the configuration section of the official installation instructions on https://www.home-assistant.io/components/media_player.dlna_dmr/ should be improved and explain, that URL must point specifically to description.xml.

It would be great if you created a pull request for this. However, not all devices name it description.xml. Still, if you can clarify this, that would be great!

Nevertheless, my problem does not yet seem to be solved. I still get errors.

It takes a while before the new version of the used UPnP-library (async_upnp_client) is used in Home Assistant. I think (hope) this will be in 0.84.

About the 412. I'll look into that, but as far as I know async_upnp_client follows the standard. It is also possible your device has too many subscriptions (due to multiple restarts of home assistant?) and returns a 412 instead.

StevenLooman commented 5 years ago

Didn't make it into 0.84. Hopefully 0.85.

stephanfevrier commented 5 years ago

It would be great if you created a pull request for this. However, not all devices name it description.xml. Still, if you can clarify this, that would be great!

I have just created my first pull request #7916 to clarify the URL to the device description.

About the 412. I'll look into that, but as far as I know async_upnp_client follows the standard. It is also possible your device has too many subscriptions (due to multiple restarts of home assistant?) and returns a 412 instead.

Your were right. After rebooting the device, the 412 errors disappeared.

Thanx!

StevenLooman commented 5 years ago

I have just created my first pull request #7916 to clarify the URL to the device description.

Great! Thank you for helping others.

Your were right. After rebooting the device, the 412 errors disappeared.

Great as well! I have changed async_upnp_client a bit (will land in home assistant in the next release) to be even more faithful to the UPnP-standard. Changes were minimal and devices should already handle this properly (i.e., lowercase to upper case, although devices should already accept any form.)

Thank you for reporting and testing!