Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add center volume commands + fix return for setVolume #73

Merged
merged 5 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/Onkyo.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ class Onkyo extends EventEmitter {
this.logger.debug(`masterVolume: ${MVL}`);
return Promise.resolve({group, data: {MVL}});
}
case 'CTL': {
const CTL = Onkyo._parseInt(command, 16);
this.deviceState.CTL = CTL;
this.logger.debug(`centerVolume: ${CTL}`);
return Promise.resolve({group, data: {CTL}});
}
case 'PWR': {
const PWR = Onkyo._parseBool(command);
this.deviceState.PWR = PWR; // power state
Expand Down Expand Up @@ -684,7 +690,18 @@ class Onkyo extends EventEmitter {
invariant(volume >= 0 && volume <= 100, 'volume should be between 0-100');
const volumeHex = volume.toString(16).toUpperCase().padStart(2, '0');
return this.sendRawCommand(`MVL${volumeHex}`)
.then(vol => parseInt(vol, 16));
.then(({MVL}) => MVL);
}
getCenterVolume() {
return this.sendCommand('AUDIO', 'STATUS_CTL')
.then(({CTL}) => CTL);
}
setCenterVolume(volume) {
invariant(_.isInteger(volume), 'volume should be an integer');
invariant(volume >= -12 && volume <= 12, 'volume should be between -12 and 12');
const volumeHex = ((volume > 0 ? '+' : '') + volume.toString(16).toUpperCase()).padStart(2, '0');
return this.sendRawCommand(`CTL${volumeHex}`)
.then(({CTL}) => CTL);
}
setSource(source) {
return this.sendCommand('SOURCE_SELECT', source);
Expand Down
8 changes: 7 additions & 1 deletion lib/onkyo.commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ const AUDIO =
Volume: 'MVLQSTN',
VOL_QSTN: 'MVLQSTN',
STATUS_VOL: 'MVLQSTN',
STATUS_MUTE: 'AMTQSTN'
STATUS_MUTE: 'AMTQSTN',
CTL_UP: 'CTLUP',
'Center Up': 'CTLUP',
CTL_DOWN: 'CTLDOWN',
'Center Down': 'CTLDOWN',
CTL_QSTN: 'CTLQSTN',
STATUS_CTL: 'CTLQSTN'
};

// Cinema Filter
Expand Down
32 changes: 31 additions & 1 deletion test/onkyo.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('Onkyo', function () {
it('pass', function () {
const vol = 50;
onkyo._sendISCPpacket.callsFake(() => {
onkyo.emit('MVL', vol.toString(16));
onkyo._parseClientPacket(`MVL${vol.toString(16)}`, pypass);
});
return onkyo.setVolume(vol)
.then((volume) => {
Expand All @@ -206,6 +206,36 @@ describe('Onkyo', function () {
});
});
});
describe('setCenterVolume', function () {
it('throws when invalid input', function () {
expect(() => onkyo.setCenterVolume('')).to.throw(Error);
expect(() => onkyo.setCenterVolume(0.1)).to.throw(Error);
expect(() => onkyo.setCenterVolume(-13)).to.throw(Error);
expect(() => onkyo.setCenterVolume(13)).to.throw(Error);
});
it('pass', function () {
const vol = 6;
onkyo._sendISCPpacket.callsFake(() => {
onkyo._parseClientPacket(`CTL+${vol.toString(16)}`, pypass);
});
return onkyo.setCenterVolume(vol)
.then((volume) => {
expect(volume).to.be.eql(vol);
});
});
});
describe('getCenterVolume', function () {
it('pass', function () {
const vol = 10;
onkyo._sendISCPpacket.callsFake(() => {
onkyo._parseClientPacket(`CTL+${vol.toString(16)}`, pypass);
});
return onkyo.getCenterVolume()
.then((volume) => {
expect(volume).to.be.eql(vol);
});
});
});
it('getDeviceState', function () {
const callFakes = [
() => onkyo._parseClientPacket('PWR01', pypass), // POWER on
Expand Down