diff --git a/lib/helpers.js b/lib/helpers.js index 77f4966..158b389 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 f8ec2e9..44f2bbf 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') @@ -162,6 +162,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() } @@ -171,6 +172,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() } @@ -558,6 +560,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) @@ -641,7 +644,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') {