bencevans / node-sonos

🔈 Sonos Media Player Interface/Client
https://www.npmjs.com/package/sonos
MIT License
702 stars 147 forks source link

getAllGroups leads to type errors #407

Closed freaktechnik closed 5 years ago

freaktechnik commented 5 years ago

Expected Behavior

getAllGroups should resolve and not raise any errors.

Current Behavior

Raises a type error (as far as I can see three times, though that may just be three players):

2019-04-04 10:32:38.501 ERROR  : sonos: TypeError: Cannot read property 'ZoneGroup' of undefined
2019-04-04 10:32:38.501 ERROR  : sonos:     at GetZoneGroupState.then (/home/dhylands/moziot/.mozilla-iot/addons/sonos-adapter/node_modules/sonos/lib/services/ZoneGroupTopology.js:46:76)
2019-04-04 10:32:38.502 ERROR  : sonos:     at <anonymous>
2019-04-04 10:32:38.502 ERROR  : sonos:     at process._tickCallback (internal/process/next_tick.js:189:7)

Possible Solution

Properly check for the property, probably. Not sure if that problem is new or not.

Sample code or executed example

As far as I can tell these errors happen when calling getAllGroups on a speaker. In my case https://github.com/freaktechnik/sonos-adapter/blob/97a4bfe828ee420e056dd12dc70c16ed995a711f/speaker.js#L224

Versions (and Environment)

Node version: v8.15.0 and v11.* node-sonos version: 1.10.0 OS: Debian (likes)

freaktechnik commented 5 years ago

Actually, the fix seems to be to add another ZoneGroupState.

From the release version (await Helpers.ParseXml(state.ZoneGroupState)) is logged as { ZoneGroupState: { ZoneGroups: { ZoneGroup: [Array] }, VanishedDevices: '' }.

But not always, for some players it's { ZoneGroups: { ZoneGroup: [ [Object], [Object], [Object], [Object], [Object] ] } }

freaktechnik commented 5 years ago

There's a second related error in the event parser (the logged object is eventData):

2019-04-04 20:10:33.053 INFO   : sonos: { ZoneGroupState:
2019-04-04 20:10:33.053 INFO   : sonos:    { ZoneGroupState: { ZoneGroups: [Object], VanishedDevices: '' } },
2019-04-04 20:10:33.053 INFO   : sonos:   AvailableSoftwareUpdate:
2019-04-04 20:10:33.053 INFO   : sonos:    { UpdateItem:
2019-04-04 20:10:33.053 INFO   : sonos:       { xmlns: 'urn:schemas-rinconnetworks-com:update-1-0',
2019-04-04 20:10:33.053 INFO   : sonos:         Type: 'Software',
2019-04-04 20:10:33.054 INFO   : sonos:         Version: '49.2-63270',
2019-04-04 20:10:33.054 INFO   : sonos:         UpdateURL:
2019-04-04 20:10:33.054 INFO   : sonos:          'http://update-firmware.sonos.com/firmware/Prod/49.2-63270-v10.1-kcxxjh-GA-1/^49.2-63270',
2019-04-04 20:10:33.054 INFO   : sonos:         DownloadSize: '0',
2019-04-04 20:10:33.054 INFO   : sonos:         ManifestURL:
2019-04-04 20:10:33.054 INFO   : sonos:          'http://update-firmware.sonos.com/firmware/Prod/49.2-63270-v10.1-kcxxjh-GA-1/update_1553855194.upm' } },
2019-04-04 20:10:33.054 INFO   : sonos:   AlarmRunSequence: 'RINCON_B8E937EC581E01400:55:0',
2019-04-04 20:10:33.054 INFO   : sonos:   ZoneGroupName: 'Schlafzimmer',
2019-04-04 20:10:33.054 INFO   : sonos:   ZoneGroupID: 'RINCON_B8E937EC581E01400:27',
2019-04-04 20:10:33.055 INFO   : sonos:   ZonePlayerUUIDsInGroup: 'RINCON_B8E937EC581E01400',
2019-04-04 20:10:33.055 INFO   : sonos:   MuseHouseholdId: 'Sonos_FanndGyYGPZRvxF1uO1SuWA4YV.dcK0ToIpbQbr1v6oI1aZ',
2019-04-04 20:10:33.055 INFO   : sonos:   AreasUpdateID: '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=' }
2019-04-04 20:10:33.055 INFO   : sonos: Unhandled Rejection
2019-04-04 20:10:33.055 ERROR  : sonos: TypeError: Cannot read property 'ZoneGroup' of undefined
2019-04-04 20:10:33.055 ERROR  : sonos:     at Object.EventParser._parseZoneGroupTopologyEvent (/home/martin/dev/sonos-adapter/node_modules/sonos/lib/events/eventParser.js:126:59)
2019-04-04 20:10:33.056 ERROR  : sonos:     at processTicksAndRejections (internal/process/next_tick.js:81:5)
magnlund commented 5 years ago

I can confirm this issue. After upgrading to Sonos 10.1 the grouping function does not work anylonger. The error message is ”cannot read property ZoneGroup of undefned”. I would be very happy for a quick fix on this. Thanks in advance. /Magnus

CajunDust commented 5 years ago

This is indeed confirmed that the Sonos API changed. I had the same issues with using the unofficial sonos app and noson... which are build on the same sonos-node code...

magnlund commented 5 years ago

The same happened in September last year. The node-sonos guys came up with a fix very fast and everything went back to normal. Hopefully this time only a minor change is required on this great API

magnlund commented 5 years ago

While waiting for a new node-sonos release replace line 46 in ZoneGroupTopology.js with this row: let groups = (await Helpers.ParseXml(state.ZoneGroupState)).ZoneGroupState.ZoneGroups.ZoneGroup That worked for me! The grouping function works again.

freaktechnik commented 5 years ago

As I said, that won't work in every case, for me not all players have that format, even though all of them claim to be on the same patch level. Plus there's also a problem with an event.

magnlund commented 5 years ago

Understood but that could be a good enough workaround while waiting for a new release

bencevans commented 5 years ago

I got caught by this issue a few days ago but am away now so can't work on this personally. Thanks for investigating and your partial fix mention @magnlund & @freaktechnik. If you're able to fix it yourselves a pull request would be much appreciated as I'm unsure any of the team will be able to put time into this for a while.

bencevans commented 5 years ago

:tada: This issue has been resolved in version 1.10.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

magnlund commented 5 years ago

Brilliant! Thanks guys;)