Skip to content

Commit

Permalink
feat: Special state for group members
Browse files Browse the repository at this point in the history
Fixed #110
  • Loading branch information
svrooij committed Sep 24, 2021
1 parent 7669ac4 commit 50f63d6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test": "eslint ./src/*.ts"
},
"dependencies": {
"@svrooij/sonos": "^2.4.1",
"@svrooij/sonos": "^2.5.0-beta.1",
"mqtt": "4.2.8",
"serilogger": "^0.3.1",
"yalm": "4.1.0",
Expand Down
6 changes: 3 additions & 3 deletions src/sonos-state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Track, ChannelValue } from '@svrooij/sonos/lib/models'
import { Track, ChannelValue, ExtendedTransportState } from '@svrooij/sonos/lib/models'
/**
* Object that keeps the state of each device,
* this is what is changed by the events and published to mqtt as a full object.
Expand All @@ -19,13 +19,13 @@ export interface SonosState extends SonosStateBase {
currentTrack: Track | string;
nextTrack: Track | string;
enqueuedMetadata: Track | string;
transportState: string;
transportState: ExtendedTransportState;
playmode: string;
bass: number;
treble: number;

}

interface SonosStateBase {
[key: string]: string | number | Track | ChannelValue<number> | ChannelValue<boolean>;
[key: string]: string | number | Track | ChannelValue<number> | ChannelValue<boolean> | ExtendedTransportState;
}
17 changes: 12 additions & 5 deletions src/sonos-to-mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ export class SonosToMqtt {
}
this.log.debug('Executed {command} for {device} ({uuid})', payload.command ?? payload.sonosCommand, correctDevice.Name, correctDevice.Uuid)
} catch (e) {
this.log.warn(e, 'Error executing {command} for {device} ({uuid})', payload.command ?? payload.sonosCommand, correctDevice.Name, correctDevice.Uuid)
if (e instanceof Error) {
this.log.warn(e, 'Error executing {command} for {device} ({uuid})', payload.command ?? payload.sonosCommand, correctDevice.Name, correctDevice.Uuid)
} else {
this.log.warn('Error executing {command} for {device} ({uuid})', payload.command ?? payload.sonosCommand, correctDevice.Name, correctDevice.Uuid)
}
this.mqtt.publish(`${correctDevice.Uuid}/error`, {
command: payload.command ?? payload.sonosCommand,
error: e
Expand Down Expand Up @@ -135,6 +139,12 @@ export class SonosToMqtt {
this.mqtt.publish(`status/${this.topicId(d.Name, d.Uuid)}/coordinator`, coordinatorUuid)
}
})
d.Events.on('transportState', (transportState) => {
this.updateState(d.Uuid, { transportState } );
if (this.config.distinct === true) {
this.mqtt.publish(`status/${this.topicId(d.Name, d.Uuid)}/state`, transportState)
}
})
if(this.config.distinct === true) {
d.Events.on(SonosEvents.CurrentTrackMetadata, (track) => {
this.mqtt.publish(`status/${this.topicId(d.Name, d.Uuid)}/track`, track)
Expand All @@ -145,9 +155,6 @@ export class SonosToMqtt {
d.Events.on(SonosEvents.Mute, (mute) => {
this.mqtt.publish(`status/${this.topicId(d.Name, d.Uuid)}/muted`, mute)
})
d.Events.on(SonosEvents.CurrentTransportStateSimple, (state) => {
this.mqtt.publish(`status/${this.topicId(d.Name, d.Uuid)}/state`, state)
})
d.Events.on(SonosEvents.Volume, (volume) => {
this.mqtt.publish(`status/${this.topicId(d.Name, d.Uuid)}/volume`, volume)
})
Expand Down Expand Up @@ -194,7 +201,7 @@ export class SonosToMqtt {
currentTrack: data.CurrentTrackMetaData,
enqueuedMetadata: data.EnqueuedTransportURIMetaData,
nextTrack: data.NextTrackMetaData,
transportState: data.TransportState,
// transportState: data.TransportState,
playmode: data.CurrentPlayMode,
})
}
Expand Down

0 comments on commit 50f63d6

Please sign in to comment.