svrooij / node-sonos-ts

:speaker: Sonos control library, use this library in your own appliction.
https://sonos-ts.svrooij.io/
MIT License
81 stars 18 forks source link

Request: Add GroupId to SonosDevice #182

Closed orensharon closed 5 months ago

orensharon commented 1 year ago

I would like to get the GroupId of each SonosDevice similary to the GroupName getter. For example:

manager.Devices.forEach(d => {
  console.log('Device %s (%s) is joined in %s', d.Name, d.Uuid, d.GroupId)
  ....

Another solution that would work, is to add the groupId to the related group events data.

This would be helpful when dealing with Group Events:

const onGroupRenderingChanged = async (data) => {
    const sonosDevice = manager.Devices.find(data.coordinatorId)
    const timestamp = Date.now()
    const deviceGroupId = sonosDevice.GroupId
    const eventGroupId = data.GroupId
    //const groupId = await sonosDevice.ZoneGroupTopologyService.GetZoneGroupAttributes()
    //        .then(attributes => attributes.CurrentZoneGroupID)
    const event = { groupId, data, timestamp }
    events.emit('group-rendering', event)
}

.....
const id = sonosDevice.uuid
sonosDevice.GroupRenderingControlService.Events.on(ServiceEvent, data => onGroupRenderingChanged({ id, data })
....
....
svrooij commented 1 year ago

Where do you need the group id for? Cannot oversee it at the moment.

orensharon commented 1 year ago

Hi,

I need the GroupId to identify the Group entity in the domain layer of my app.

When a GroupZoneTopology event is triggered, I analyze the changes within each group and emit a corresponding event to update the domain's state.

Similarly, a GroupRenderingControl event triggers another event with the GroupId and relevant data to modify the domain's state.

I'm considering using events like Coordinator to track group changes, but I'm still figuring out the best approach.

I'm open to exploring other solutions if you have any suggestions or alternatives.

Thanks.

svrooij commented 1 year ago

Have you checked the events on the manager?

Each player already received updates if the coordinator changes and sets the .Coordinator on the player.

github-actions[bot] commented 5 months ago

:tada: This issue has been resolved in version 2.6.0-beta.8 :tada:

The release is available on:

Your semantic-release bot :package::rocket: