From 8c09c235dd0e84e9c32c0b5f062dd73160880bd1 Mon Sep 17 00:00:00 2001 From: Wulf Weich Date: Thu, 8 Sep 2022 21:37:27 +0200 Subject: [PATCH] ensure 2 digits for volumeHex (#71) (again) (#142) * ensure 2 digits for volumeHex (#71) (again) * fix return for setVolume (#73) (again) * fix test --- lib/Onkyo.js | 6 +++--- test/onkyo.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Onkyo.js b/lib/Onkyo.js index 2dfa157..785edb2 100644 --- a/lib/Onkyo.js +++ b/lib/Onkyo.js @@ -734,11 +734,11 @@ class Onkyo extends EventEmitter { setVolume(volume, zone) { invariant(_.isInteger(volume), 'volume should be an integer'); invariant(volume >= 0, 'volume should be 0 or above'); - const volumeHex = volume.toString(16).toUpperCase(); + const volumeHex = volume.toString(16).toUpperCase().padStart(2, '0'); const rawCommand = OnkyoCmds.getZoneCommand('MVL', zone) + volumeHex; return this.pwrOn(zone) - .then(() => this.sendRawCommand(rawCommand) - .then(vol => parseInt(vol, 16))); + .then(() => this.sendRawCommand(rawCommand)) + .then(({MVL}) => MVL); } getSource(zone) { return this.sendCommand(OnkyoCmds.getZoneCommand('SOURCE_SELECT', zone), 'STATUS') diff --git a/test/onkyo.js b/test/onkyo.js index cab0c41..95c31f5 100644 --- a/test/onkyo.js +++ b/test/onkyo.js @@ -196,7 +196,7 @@ describe('Onkyo', function () { const vol = 50; const callFakes = [ () => onkyo._parseClientPacket('PWR01', pypass), // POWER on - () => onkyo.emit('MVL', vol.toString(16)) // VOL 1 + () => onkyo._parseClientPacket(`MVL${vol.toString(16)}`, pypass) // VOL 1 ]; _.each(callFakes, (callFake, index) => { onkyo._sendISCPpacket.onCall(index).callsFake(callFake);