Skip to content

Commit b5eabb8

Browse files
authored
Merge pull request #315 from hklages/remove_sub
Remove sub
2 parents 959feca + b00b2c1 commit b5eabb8

File tree

3 files changed

+95
-3
lines changed

3 files changed

+95
-3
lines changed

src/Helper.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,43 @@ module.exports = {
117117
return item.replace(/:LR|:RR/, '')
118118
})
119119
},
120+
121+
/** Returns the UUID of the subwoofer.
122+
* @param {string} mapString string from HTSatChanMapSet or channelMapSet
123+
*
124+
* @returns {"Promise<string>"} subwoofer UUID
125+
*
126+
* @throws {error}
127+
*
128+
*/
129+
// Example
130+
// eslint-disable-next-line max-len
131+
// RINCON_48A6B8B5614E01400:LF,RF;RINCON_38420B92ABE601400:RR;RINCON_7828CA042C8401400:LR;RINCON_542A1B108A6201400:SW
132+
133+
extractSubwooferUuid: async (mapString) => {
134+
debug('method:%s', 'extractSubwooferUuid')
135+
136+
if (!module.exports.isTruthy(mapString)) {
137+
throw new Error('invalid parameter - invalid/missing')
138+
}
139+
if (typeof mapString !== 'string') {
140+
throw new Error('invalid parameter - is not string')
141+
}
142+
143+
if (!mapString.includes(';')) {
144+
throw new Error('invalid parameter - no subwoofer (missing ;)')
145+
}
146+
const uuidsPlusChannel = mapString.split(';')
147+
const subwooferUuidArray = uuidsPlusChannel.filter((item) => {
148+
return item.includes(':SW')
149+
})
150+
if ((subwooferUuidArray.length !== 1)) {
151+
throw new Error('invalid parameter - no subwoofer found')
152+
}
153+
154+
// remove identifier :SW
155+
return subwooferUuidArray[0].replace(/:SW/, '')
156+
},
120157

121158
/** Converts hh:mm:ss time to milliseconds. Does not check input!
122159
* No validation: hh 0 to 23, mm 0 to 59 ss 0 59, : must exist

src/sonos-universal.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
{ cmd: "household.get.sonosplaylists" },
184184
{ cmd: "household.get.sonosplaylisttracks" },
185185
{ cmd: "household.remove.satellites" },
186+
{ cmd: "household.remove.subwoofer" },
186187
{ cmd: "household.remove.sonosplaylist" },
187188
{ cmd: "household.separate.group" },
188189
{ cmd: "household.separate.stereopair" },

src/sonos-universal.js

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const { executeActionV8, failureV2, getDeviceInfo, getDeviceProperties, getMusic
3131
} = require('./Extensions.js')
3232

3333
const { isTruthy, isTruthyProperty, isTruthyPropertyStringNotEmpty, validRegex,
34-
validToInteger, encodeHtmlEntity, extractSatellitesUuids, validTime, validPropertyRequiredRegex,
35-
validPropertyRequiredInteger, validPropertyRequiredOnOff
34+
validToInteger, encodeHtmlEntity, extractSatellitesUuids, extractSubwooferUuid, validTime,
35+
validPropertyRequiredRegex, validPropertyRequiredInteger, validPropertyRequiredOnOff
3636
} = require('./Helper.js')
3737

3838
const { SonosDevice, MetaDataHelper } = require('@svrooij/sonos/lib')
@@ -112,6 +112,7 @@ module.exports = function (RED) {
112112
'household.get.sonosplaylisttracks': householdGetSonosPlaylistTracks,
113113
'household.remove.satellites': householdRemoveSatellites,
114114
'household.remove.sonosplaylist': householdRemoveSonosPlaylist,
115+
'household.remove.subwoofer': householdRemoveSubwoofer,
115116
'household.separate.group': householdSeparateGroup,
116117
'household.separate.stereopair': householdSeparateStereoPair,
117118
'household.set.alarmtime': householdSetAlarmTime,
@@ -2802,7 +2803,7 @@ module.exports = function (RED) {
28022803
}
28032804

28042805
/**
2805-
* Removes only the satellites (not the subwoofer) of players.
2806+
* Removes only the satellites (not the subwoofer) of a player.
28062807
* All players will become visible again. Github #238
28072808
* @param {object} msg incoming message
28082809
* @param {string} msg.payload - main SONOS-Playername, is visible
@@ -2850,6 +2851,59 @@ module.exports = function (RED) {
28502851
return {}
28512852
}
28522853

2854+
/**
2855+
* Removes only the subwoofer of a player.
2856+
* The subwoofer will become visible again.
2857+
* @param {object} msg incoming message
2858+
* @param {string} msg.payload - main SONOS-Playername, is visible
2859+
* @param {object} tsPlayer any sonos-ts player with .urlObject as Javascript build-in URL
2860+
*
2861+
* @returns {promise<object>} {}
2862+
*
2863+
* @throws {error} 'all groups data undefined',
2864+
* 'main player name left was not found'
2865+
* @throws {error} all methods
2866+
*
2867+
* CAUTION: The command has to be send to the main player!
2868+
*
2869+
*/
2870+
async function householdRemoveSubwoofer (msg, tsPlayer) {
2871+
debug('command:%s', 'householdRemoveSubwoofer')
2872+
2873+
const mainPlayername = validRegex(msg, 'payload', REGEX_ANYCHAR, 'main player name')
2874+
2875+
// Get all player and find the given one
2876+
const allGroupsData = await getGroupsAll(tsPlayer, true)
2877+
if (!isTruthy(allGroupsData)) {
2878+
throw new Error(`${PACKAGE_PREFIX} all groups data undefined`)
2879+
}
2880+
// - flatten the array of groups of player and search for main player
2881+
const flatArrayOfPlayer = [].concat.apply([], allGroupsData)
2882+
const mainPlayerData = flatArrayOfPlayer.find(singlePlayer => {
2883+
return singlePlayer.playerName === mainPlayername
2884+
})
2885+
if (mainPlayerData === undefined) {
2886+
throw new Error(`${PACKAGE_PREFIX} could not find given main player`)
2887+
}
2888+
2889+
// Get Satellites UUIDs
2890+
// :SW can be in htSatChanMapSet or channelMapSet
2891+
let mapSet = mainPlayerData.htSatChanMapSet
2892+
if (!mapSet.includes(':SW')) {
2893+
mapSet = mainPlayerData.channelMapSet
2894+
}
2895+
2896+
const subwooferUuid = await extractSubwooferUuid(mapSet)
2897+
console.log(subwooferUuid)
2898+
2899+
// IMPORTANT: Must be send to main player
2900+
const tsMainPlayer = new SonosDevice(mainPlayerData.urlObject.hostname)
2901+
await tsMainPlayer.DevicePropertiesService.RemoveHTSatellite(
2902+
{ 'SatRoomUUID': subwooferUuid })
2903+
2904+
return {}
2905+
}
2906+
28532907
/**
28542908
* Household test player connection
28552909
* @param {object} msg incoming message

0 commit comments

Comments
 (0)