From d2d8a4f2f40d59a390574a9cd04c10997ce612c0 Mon Sep 17 00:00:00 2001 From: Stephan van Rooij Date: Fri, 27 Dec 2019 12:52:12 +0100 Subject: [PATCH] fix: Allow joining groups Fixes #22 --- examples/zones.js | 7 +++++++ src/helpers/zone-helper.ts | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 examples/zones.js diff --git a/examples/zones.js b/examples/zones.js new file mode 100644 index 0000000..2565b3a --- /dev/null +++ b/examples/zones.js @@ -0,0 +1,7 @@ +const SonosDevice = require('../lib').SonosDevice + +const sonos = new SonosDevice(process.env.SONOS_HOST || '192.168.96.56') + +sonos.JoinGroup('keuken') + .then(console.log) + .catch(console.error) diff --git a/src/helpers/zone-helper.ts b/src/helpers/zone-helper.ts index 8212f3c..8204b5f 100644 --- a/src/helpers/zone-helper.ts +++ b/src/helpers/zone-helper.ts @@ -3,12 +3,12 @@ import { XmlHelper } from '../' import { URL } from 'url' export class ZoneHelper { static ParseZoneGroupStateResponse(zoneGroupStateResponse: GetZoneGroupStateResponse): ZoneGroup[] { - return this.DecodedObjectToGroups(XmlHelper.DecodeAndParseXml(zoneGroupStateResponse.ZoneGroupState)) + return ZoneHelper.DecodedObjectToGroups(XmlHelper.DecodeAndParseXml(zoneGroupStateResponse.ZoneGroupState)) } static DecodedObjectToGroups(state: any): ZoneGroup[] { const groups = Array.isArray(state.ZoneGroupState.ZoneGroups.ZoneGroup) ? state.ZoneGroupState.ZoneGroups.ZoneGroup : [state.ZoneGroupState.ZoneGroups.ZoneGroup] - return groups.map(this.ParseGroup) + return groups.map(ZoneHelper.ParseGroup) } private static ParseGroup(group: any): ZoneGroup {