From c8241a1bbe136e15f6784ec04ece74c52198f6f2 Mon Sep 17 00:00:00 2001 From: blanck Date: Sat, 28 May 2022 18:08:41 +0200 Subject: [PATCH] fix: Support for group controls --- lib/sonos.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/lib/sonos.js b/lib/sonos.js index 4ad7f95..e817b4e 100644 --- a/lib/sonos.js +++ b/lib/sonos.js @@ -286,6 +286,27 @@ Sonos.prototype.getMuted = async function () { return this.renderingControlService().GetMute() } +/** + * Get Current Group Volume + * @returns {Number} The current volume + */ +Sonos.prototype.getGroupVolume = async function () { + debug('Sonos.getGroupVolume()') + if (this._isSubscribed && this._volume) return this._volume + return this.groupRenderingControlService().GetGroupVolume() +} + +/** + * Get Current Group Muted + * @returns {Boolean} + */ +Sonos.prototype.getGroupMuted = async function () { + debug('Sonos.getGroupMuted()') + if (this._isSubscribed && this._mute) return this._mute + return this.groupRenderingControlService().GetGroupMute() +} + + /** * Resumes Queue or Plays Provided URI * @param {String|Object} options Optional - URI to a Audio Stream or Object with play options @@ -682,6 +703,27 @@ Sonos.prototype.adjustVolume = async function (volumeAdjustment, channel = 'Mast return this.renderingControlService().SetRelativeVolume(volumeAdjustment, channel) } +/** + * Set Group Volume + * @param {number} volume 0..100 + * @param {string} channel What channel to change, `Master` is default. + * @returns {Object} + */ +Sonos.prototype.setGroupVolume = async function (volume, channel = 'Master') { + debug('Sonos.setGroupVolume(%j)', volume) + return this.groupRenderingControlService().SetGroupVolume(volume, channel) +} + +/** + * Adjust Group volume + * @param {number} volumeAdjustment The relative volume adjustment + * @param {string} channel The channel you want to set, `Master` is default. + */ +Sonos.prototype.adjustGroupVolume = async function (volumeAdjustment, channel = 'Master') { + debug('Sonos.adjustGroupVolume(%j)', volumeAdjustment) + return this.groupRenderingControlService().SetRelativeGroupVolume(volumeAdjustment, channel) +} + /** * Configure Sleep Timer * @param {String} sleepTimerDuration @@ -704,6 +746,18 @@ Sonos.prototype.setMuted = async function (muted, channel = 'Master') { return this.renderingControlService().SetMute(muted, channel) } +/** + * Set Group Muted + * @param {Boolean} muted + * @param {string} channel What channel to change, `Master` is default. + * @returns {Object} + */ +Sonos.prototype.setGroupMuted = async function (muted, channel = 'Master') { + debug('Sonos.setGroupMuted(%j)', muted) + if (typeof muted === 'string') muted = !!parseInt(muted, 10) + return this.groupRenderingControlService().SetGroupMute(muted, channel) +} + /** * Get device balance as number from -100 (full left) to +100 (full right), where 0 is left and right equal * @returns {Promise} @@ -1003,6 +1057,10 @@ Sonos.prototype.renderingControlService = function () { return new Services.RenderingControl(this.host, this.port) } +Sonos.prototype.groupRenderingControlService = function () { + return new Services.GroupRenderingControl(this.host, this.port) +} + Sonos.prototype.zoneGroupTopologyService = function () { return new Services.ZoneGroupTopology(this.host, this.port) }