home-assistant-libs / netdisco

:mag_right: Python library to scan local network for services and devices.
Other
266 stars 147 forks source link

Yamaha R-N301 causes exception yamaha.py #206

Closed vrih closed 6 years ago

vrih commented 6 years ago

My yamaha R-N301 causes an exception in yamaha.py with the following stack trace:

Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/discovery.py", line 168, in scan_devices
    results = await hass.async_add_job(_discover, netdisco)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/discovery.py", line 197, in _discover
    for service in netdisco.get_info(disc):
  File "/usr/local/lib/python3.6/site-packages/netdisco/discovery.py", line 97, in get_info
    return self.discoverables[dis].get_info()
  File "/usr/local/lib/python3.6/site-packages/netdisco/discoverables/__init__.py", line 24, in get_info
    return [self.info_from_entry(entry) for entry in self.get_entries()]
  File "/usr/local/lib/python3.6/site-packages/netdisco/discoverables/__init__.py", line 24, in <listcomp>
    return [self.info_from_entry(entry) for entry in self.get_entries()]
  File "/usr/local/lib/python3.6/site-packages/netdisco/discoverables/yamaha.py", line 27, in info_from_entry
    service['X_unitDescURL'][1:])
KeyError: 'X_unitDescURL'

The R-N301 is an early Yamaha network player that doesn't quite follow the same protocol as the later musiccast players. It does haven an equivalent to X_unitDescURL, but replacing this in just causes the downstream library to crash, and as this is a discontinued player I'm not sure fixing that is the right way to go.

At the simplest level I was thinking just replacing this into https://github.com/home-assistant/netdisco/blob/master/netdisco/discoverables/yamaha.py#L31:

    def get_entries(self):
        """Get all the Yamaha uPnP entries."""
        devices = self.find_by_device_description({
            "manufacturer": "Yamaha Corporation",
            "deviceType": "urn:schemas-upnp-org:device:MediaRenderer:1"
        })
        return [device for device in devices if
                device.description['device']['modelNumber'] not in
                INCOMPATIBLE_MODELS]

with a static list of incompatible model numbers, but I'm not sure if there's a better way.

balloob commented 6 years ago

if it also doesn't work with the downstream lib, then let's just filter it out .