diff --git a/src/device-control.ts b/src/device-control.ts index 2ee26c7..9d55870 100644 --- a/src/device-control.ts +++ b/src/device-control.ts @@ -1,11 +1,16 @@ import { SonosCommands } from "./sonos-commands"; export class DeviceControl { - public readonly command?: SonosCommands + public readonly command?: SonosCommands; + public readonly replyTopic?: string; constructor(command?: string, public readonly sonosCommand?: string, public readonly input?: any) { if(command !== undefined && Object.values(SonosCommands).some(v => v === command.toLowerCase())) { this.command = command.toLowerCase() as SonosCommands; } + + if(command === SonosCommands.AdvancedCommand && input.reply) { + this.replyTopic = input.reply; + } } isValid(): boolean { diff --git a/src/sonos-to-mqtt.ts b/src/sonos-to-mqtt.ts index fb63cd4..5811453 100644 --- a/src/sonos-to-mqtt.ts +++ b/src/sonos-to-mqtt.ts @@ -87,7 +87,10 @@ export class SonosToMqtt { return; } try { - await SonosCommandMapping.ExecuteControl(correctDevice, payload) + const response = await SonosCommandMapping.ExecuteControl(correctDevice, payload); + if(payload.replyTopic) { + this.mqtt.publish(`${correctDevice.Uuid}/${payload.replyTopic}`, JSON.stringify(response)); + } 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)