Skip to content

Commit

Permalink
Add equalizer info to state object
Browse files Browse the repository at this point in the history
  • Loading branch information
jishi committed Mar 14, 2017
1 parent 6faedf8 commit 66191c7
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
25 changes: 23 additions & 2 deletions lib/models/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ function getState(playerInternal, coordinatorInternal, sub) {
var elapsedTime = coordinatorInternal.relTime + Math.floor(diff / 1000);

const state = {
currentTrack: coordinatorInternal.currentTrack,
nextTrack: coordinatorInternal.nextTrack,
volume: playerInternal.volume,
mute: playerInternal.mute,
equalizer: playerInternal.equalizer,
currentTrack: coordinatorInternal.currentTrack,
nextTrack: coordinatorInternal.nextTrack,
trackNo: coordinatorInternal.trackNo,
elapsedTime: elapsedTime,
elapsedTimeFormatted: formatTime(elapsedTime),
Expand Down Expand Up @@ -384,6 +385,26 @@ function Player(data, listener, system) {
if (data.subenabled) {
_this.sub.enabled = data.subenabled.val == '1';
}

if (data.bass) {
_this._state.equalizer.bass = parseInt(data.bass.val);
}

if (data.treble) {
_this._state.equalizer.treble = parseInt(data.treble.val);
}

if (data.dialoglevel) {
_this._state.equalizer.speechEnhancement = data.dialoglevel.val === '1';
}

if (data.nightmode) {
_this._state.equalizer.nightMode = data.nightmode.val === '1';
}

if (data.loudness) {
_this._state.equalizer.loudness = data.loudness.val === '1';
}
}

function groupMuteHandler(uuid, mute) {
Expand Down
7 changes: 6 additions & 1 deletion lib/types/empty-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ const EMPTY_STATE = Object.freeze({
volume: 0,
mute: false,
trackNo: 0,
playbackState: 'STOPPED'
playbackState: 'STOPPED',
equalizer: {
bass: 0,
treble: 0,
loudness: false
}
});

module.exports = EMPTY_STATE;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sonos-discovery",
"version": "1.4.0",
"version": "1.4.1",
"description": "A simple node library for managing your Sonos system",
"author": "Jimmy Shimizu <[email protected]>",
"repository": {
Expand Down
16 changes: 16 additions & 0 deletions test/data/renderingControlLastChange.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,21 @@
],
"outputfixed": {
"val": "0"
},
"bass": {
"val": "3"
},
"treble":{
"val": "-2"
},
"dialoglevel": {
"val": "1"
},
"nightmode": {
"val": "1"
},
"loudness": {
"channel": "Master",
"val": "1"
}
}
32 changes: 31 additions & 1 deletion test/unit/models/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ describe('Player', () => {
});
});

describe('when volume event occurs', () => {
describe('when rendering control event occurs', () => {
it('Updates volume', () => {
let lastChange = require('../../data/renderingControlLastChange.json');
listener.on.withArgs('last-change').yield('RINCON_00000000000001400', lastChange);
Expand All @@ -321,6 +321,36 @@ describe('Player', () => {
expect(player.outputFixed).equals(true);
});

it('loudness is true', () => {
let lastChange = require('../../data/renderingControlLastChange.json');
listener.on.withArgs('last-change').yield('RINCON_00000000000001400', lastChange);
expect(player.state.equalizer.loudness).equals(true);
});

it('bass is 3', () => {
let lastChange = require('../../data/renderingControlLastChange.json');
listener.on.withArgs('last-change').yield('RINCON_00000000000001400', lastChange);
expect(player.state.equalizer.bass).equals(3);
});

it('treble is -2', () => {
let lastChange = require('../../data/renderingControlLastChange.json');
listener.on.withArgs('last-change').yield('RINCON_00000000000001400', lastChange);
expect(player.state.equalizer.treble).equals(-2);
});

it('speech enhancement is true', () => {
let lastChange = require('../../data/renderingControlLastChange.json');
listener.on.withArgs('last-change').yield('RINCON_00000000000001400', lastChange);
expect(player.state.equalizer.speechEnhancement).equals(true);
});

it('nightMode is true', () => {
let lastChange = require('../../data/renderingControlLastChange.json');
listener.on.withArgs('last-change').yield('RINCON_00000000000001400', lastChange);
expect(player.state.equalizer.nightMode).equals(true);
});

it('emits event', () => {
let lastChange = require('../../data/renderingControlLastChange.json');
listener.on.withArgs('last-change').yield('RINCON_00000000000001400', lastChange);
Expand Down

0 comments on commit 66191c7

Please sign in to comment.