From f9194cd6adf5b61f47d51b394ef2ffb60c6619ae Mon Sep 17 00:00:00 2001 From: Stephan van Rooij Date: Wed, 7 Feb 2018 10:35:11 +0100 Subject: [PATCH 1/2] chore: Splitted debugging to separate namespaces --- lib/helpers.js | 2 +- lib/services/Service.js | 2 +- lib/sonos.js | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index 160adaa..cf3e9aa 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -5,7 +5,7 @@ * @requires 'xml2js */ -const debug = require('debug')('sonos') +const debug = require('debug')('sonos:helpers') const parseString = require('xml2js').parseString /** diff --git a/lib/services/Service.js b/lib/services/Service.js index 4f9f70c..2f1e2d7 100644 --- a/lib/services/Service.js +++ b/lib/services/Service.js @@ -10,7 +10,7 @@ const request = require('request-promise-native') const parseString = require('xml2js').parseString -const debug = require('debug')('sonos-service') +const debug = require('debug')('sonos:service') const Helpers = require('../helpers') /** diff --git a/lib/sonos.js b/lib/sonos.js index 95bd01e..0301eb9 100644 --- a/lib/sonos.js +++ b/lib/sonos.js @@ -17,7 +17,7 @@ const DEVICE_ENDPOINT = '/DeviceProperties/Control' const util = require('util') const EventEmitter = require('events').EventEmitter const request = require('request-promise-native') -const debug = require('debug')('sonos') +const debug = require('debug')('sonos:main') const Listener = require('./events/adv-listener') const Helpers = require('./helpers') @@ -653,7 +653,9 @@ Sonos.prototype.playNotification = async function (options) { return new Promise(async (resolve, reject) => { debug('sonos.playNotification(%j)', options) const state = await this.getCurrentState() + debug('Current state %j', state) const wasPlaying = (state === 'playing' || state === 'transitioning') + debug('Was playing %j', wasPlaying) const wasListening = Listener.isListening() let volume = 0 if (typeof options === 'object') { From 59f43d803b4384027ddb028c90efbe1e7f5bcb81 Mon Sep 17 00:00:00 2001 From: Stephan van Rooij Date: Wed, 7 Feb 2018 11:21:10 +0100 Subject: [PATCH 2/2] fix: sonos now returns state and volume from listener. If the event listener is in use the `getCurrentState()` and `getMuted()` now return data from the listener. Not fetched separatly. --- lib/sonos.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/sonos.js b/lib/sonos.js index 0301eb9..70d5b54 100644 --- a/lib/sonos.js +++ b/lib/sonos.js @@ -165,6 +165,7 @@ Sonos.prototype.currentTrack = async function () { */ Sonos.prototype.getVolume = async function () { debug('Sonos.getVolume()') + if (this._isSubscribed && this._volume) return this._volume return this.renderingControlService().GetVolume() } @@ -174,6 +175,7 @@ Sonos.prototype.getVolume = async function () { */ Sonos.prototype.getMuted = async function () { debug('Sonos.getMuted()') + if (this._isSubscribed && this._mute) return this._mute return this.renderingControlService().GetMute() } @@ -561,6 +563,7 @@ Sonos.prototype.getTopology = async function () { */ Sonos.prototype.getCurrentState = function () { debug('Sonos.currentState()') + if (this._isSubscribed && this._state) return this._state return this.avTransportService().GetTransportInfo() .then(result => { return Helpers.TranslateState(result.CurrentTransportState)