diff --git a/src/Accessories/ControlUnit.ts b/src/Accessories/ControlUnit.ts index 3e99062..eecf3c1 100644 --- a/src/Accessories/ControlUnit.ts +++ b/src/Accessories/ControlUnit.ts @@ -198,9 +198,15 @@ export class ControlUnit implements IAccessory { .on("set", callbackify(this.onSetVolumeSelector)); } - //TODO + /** + * Event handler for SET volume characteristic + */ private onSetVolumeSelector = async (value: any) => { this.log(`set volume + ${value}`); + switch (value) { + case 0: this.dataProvider.volumeUp(this.name); break; + case 1: this.dataProvider.volumeDown(this.name); break; + } } /********************* diff --git a/src/DataProviders/HarmonyDataProvider.ts b/src/DataProviders/HarmonyDataProvider.ts index d353d62..26d017d 100644 --- a/src/DataProviders/HarmonyDataProvider.ts +++ b/src/DataProviders/HarmonyDataProvider.ts @@ -170,11 +170,23 @@ class HarmonyDataProvider { } public volumeUp = async (controlUnitName: string) => { - + let volumeUpCommand: string = "Volume Up" + if (this.states[controlUnitName]) { + let volumeDevice: IDevice = this.getDeviceFromName(this.states[controlUnitName]!.currentActivity.volumeDeviceId); + if (volumeDevice.supportsCommand(volumeUpCommand)) { + this.sendCommand(volumeDevice.getCommand(volumeUpCommand)); + } + } } public volumeDown = async (controlUnitName: string) => { - + let volumeDownCommand: string = "Volume Down" + if (this.states[controlUnitName]) { + let volumeDevice: IDevice = this.getDeviceFromName(this.states[controlUnitName]!.currentActivity.volumeDeviceId); + if (volumeDevice.supportsCommand(volumeDownCommand)) { + this.sendCommand(volumeDevice.getCommand(volumeDownCommand)); + } + } } public sendKeyPress = async (controlUnitName: string) => {