Skip to content

Commit

Permalink
ensure 2 digits for volumeHex (#71) (again) (#142)
Browse files Browse the repository at this point in the history
* ensure 2 digits for volumeHex (#71) (again)

* fix return for setVolume (#73) (again)

* fix test
  • Loading branch information
wweich authored Sep 8, 2022
1 parent e813c91 commit 8c09c23
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/Onkyo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion test/onkyo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8c09c23

Please sign in to comment.