StevenLooman / async_upnp_client

Async UPnP Client for Python
Other
46 stars 37 forks source link

0.14.3 traceback / VolumeDB #32

Closed stp6778 closed 5 years ago

stp6778 commented 5 years ago

Hi, I upgrade to 0.14.3, works fine with my heos speakers, but there is a traceback :

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 406, in start
    resp = await task
  File "/config/deps/lib/python3.6/site-packages/async_upnp_client/aiohttp.py", line 167, in _handle_request
    status = await self.event_handler.handle_notify(headers, body)
  File "/config/deps/lib/python3.6/site-packages/async_upnp_client/event_handler.py", line 104, in handle_notify
    service.notify_changed_state_variables(changes)
  File "/config/deps/lib/python3.6/site-packages/async_upnp_client/client.py", line 325, in notify_changed_state_variables
    self.on_event(self, changed_state_variables)
  File "/config/deps/lib/python3.6/site-packages/async_upnp_client/profiles/dlna.py", line 201, in _on_event
    dlna_handle_notify_last_change(state_variable)
  File "/config/deps/lib/python3.6/site-packages/async_upnp_client/profiles/dlna.py", line 115, in dlna_handle_notify_last_change
    service.notify_changed_state_variables(changes_0)
  File "/config/deps/lib/python3.6/site-packages/async_upnp_client/client.py", line 312, in notify_changed_state_variables
    state_var = self.state_variable(name)
  File "/config/deps/lib/python3.6/site-packages/async_upnp_client/client.py", line 283, in state_variable
    raise KeyError(name)
KeyError: 'VolumeDB'

All media_player controls are OK, I just comment the raise command to suppress the traceback.

Regards.

StevenLooman commented 5 years ago

Thank you for reporting this. Curious, it appears that your HEOS speaker reports that the state variable VolumeDB has changed, but it does not have this state variable. Perhaps the state variable is named differently (Volumedb instead of VolumeDB.)

I'll make the code a bit more robust to log it is missing the state variable, instead of raising an error.

Just to check, can you run the following command:

upnp-client --pprint subscribe http://192.168.178.69:49152/description.xml \*

Replace the URL with the one of your HEOS device. I think you know what it should be. If not, you can run upnp-client search, which will give you all UPnP services/devices in your network. Then, change the volume of your device.

This should give something like the following:

{
    "timestamp": 1548844140.3578146,
    "service_id": "urn:upnp-org:serviceId:RenderingControl",
    "service_type": "urn:schemas-upnp-org:service:RenderingControl:1",
    "state_variables": {
        "LastChange": "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/AVT_RCS\">\n<InstanceID val=\"0\">\n<Volume channel=\"Master\" val=\"23\"/>\n</InstanceID>\n</Event>\n"
    }
}

We're interesting in the LastChange variable. Can you report the results?

Also, can you dump the XML files (device description and service descriptions) and show them? This will tell us which state variables are available. It should be something like this, but then for VolumeDB:

    <stateVariable sendEvents="no">
      <name>Volume</name>
      <dataType>ui2</dataType>
      <allowedValueRange>
        <minimum>0</minimum>
        <maximum>100</maximum>
        <step>1</step>
      </allowedValueRange>
    </stateVariable>
stp6778 commented 5 years ago

Volume and VolumeDB state variables changes at the same time. The problem seems to be a different name between state variable name A_ARG_TYPE_VolumeDB and lastchange name VolumeDB Not sure it's a good way to name state variables, this should be a bad implementation from Denon...

{
    "timestamp": 1548880295.997434,
    "service_id": "urn:upnp-org:serviceId:RenderingControl",
    "service_type": "urn:schemas-upnp-org:service:RenderingControl:1",
    "state_variables": {
        "LastChange": "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/RCS/\"><InstanceID val=\"0\"><Volume channel=\"Master\" val=\"20\"/><VolumeDB channel=\"Master\" val=\"20\"/></InstanceID></Event>"
    }
}
<stateVariable sendEvents="no">
 <name>A_ARG_TYPE_VolumeDB</name>
 <dataType>i2</dataType>
 <defaultValue>0</defaultValue>
 <allowedValueRange>
  <minimum>0</minimum>
  <maximum>100</maximum>
  <step>1</step>
 </allowedValueRange>
</stateVariable>
<stateVariable sendEvents="no">
 <name>Volume</name>
 <dataType>ui2</dataType>
 <defaultValue>0</defaultValue>
 <allowedValueRange>
  <minimum>0</minimum>
  <maximum>100</maximum>
  <step>1</step>
 </allowedValueRange>
</stateVariable>
StevenLooman commented 5 years ago

Thanks! You are right, the name of the state variable is wrong. The RenderingControl:3 specs state that the name must be VolumeDB.

You could file a report with Denon. Or you can use your own hack and/or wait a bit longer before a new version of async_upnp_client lands in home assistant. (I'll try to get this ready this weekend.) I'm sure you'll help others too if you report this with Denon.

stp6778 commented 5 years ago

I have sent an email to denon but I'm not sure they will do something. I comment the keyerror command and waiting your next release. Thanks for all your work.

StevenLooman commented 5 years ago

0.14.4 was released and landed in home assistant. The fix should be available next version.