Skip to content

Commit

Permalink
Merge pull request #160 from svrooij/feature/22Q2
Browse files Browse the repository at this point in the history
Emit new devices and keep playmode
  • Loading branch information
svrooij authored Apr 29, 2022
2 parents f633223 + baf4f34 commit cebaa47
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion src/sonos-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
GetZoneInfoResponse, GetZoneAttributesResponse, AddURIToQueueResponse, AVTransportServiceEvent, RenderingControlServiceEvent, MusicService, AccountData,
} from './services';
import {
PlayNotificationOptions, Alarm, TransportState, GroupTransportState, ExtendedTransportState, ServiceEvents, SonosEvents, PatchAlarm, PlayTtsOptions, BrowseResponse, ZoneGroup, ZoneMember,
PlayNotificationOptions, Alarm, TransportState, GroupTransportState, ExtendedTransportState, ServiceEvents, SonosEvents, PatchAlarm, PlayTtsOptions, BrowseResponse, ZoneGroup, ZoneMember, PlayMode,
} from './models';
import { StrongSonosEvents } from './models/strong-sonos-events';
import { EventsError } from './models/event-errors';
Expand Down Expand Up @@ -782,6 +782,10 @@ export default class SonosDevice extends SonosDeviceBase {
this.Events.emit(SonosEvents.EnqueuedTransportUri, this.enqueuedTransportUri ?? '');
if (data.EnqueuedTransportURIMetaData !== undefined && typeof data.EnqueuedTransportURIMetaData !== 'string') this.Events.emit(SonosEvents.EnqueuedTransportMetadata, data.EnqueuedTransportURIMetaData);
}

if (data.CurrentPlayMode) {
this.currentPlayMode = data.CurrentPlayMode;
}
}

private boundHandleRenderingControlEvent = this.handleRenderingControlEvent.bind(this);
Expand Down Expand Up @@ -870,6 +874,19 @@ export default class SonosDevice extends SonosDeviceBase {
// #endregion

// #region Properties
private currentPlayMode?: PlayMode;

/**
* Current play mode, only set when subscribed to events.
*
* @readonly
* @type {(string | undefined)}
* @memberof SonosDevice
*/
public get CurrentPlayMode(): PlayMode | undefined {
return this.currentPlayMode;
}

private currentTrackUri?: string;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/sonos-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class SonosManager {
.forEach((m) => {
const newDevice = new SonosDevice(m.host, m.port, m.uuid, m.name, { coordinator: m.uuid === g.coordinator.uuid ? undefined : coordinator, name: g.name, managerEvents: this.events });
this.devices.push(newDevice);
this.events.emit('NewDevice', coordinator);
this.events.emit('NewDevice', newDevice);
});

g.members.forEach((m) => {
Expand Down

0 comments on commit cebaa47

Please sign in to comment.