Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squeezebox multiroom support #312

Merged
merged 4 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,22 @@ See [Speaker group management](#speaker-group-management) for example usage.
**Supported platforms**
- sonos
- soundtouch
- yamaha_musiccast<sup>[1](#speaker_foot1)</sup>
- squeezebox<sup>[2](#speaker_foot2)</sup>
- bluesound<sup>[2](#speaker_foot2)</sup>
- snapcast<sup>[2](#speaker_foot2)</sup>
- yamaha_musiccast<sup>[1](#speaker_foot1)</sup>

| Name | Type | Default | Description |
|------|------|---------|-------------|
| entities | list | **required** | A list containing [speaker entities](#speaker-entity-object) of one of supported platforms, to enable group management of those speakers.
| platform | string | 'sonos' | The media_player platform to control. `sonos`, `soundtouch`, `snapcast`, `bluesound` or `yamaha_musiccast`<sup>[1](#speaker_foot1)</sup>.
| platform | string | 'sonos' | The media_player platform to control. `sonos`, `soundtouch`, `snapcast`, `bluesound`, `squeezebox` or `yamaha_musiccast`<sup>[1](#speaker_foot1)</sup>.
| sync_volume | boolean | optional | Keep volume Synchronize between grouped speakers.
| expanded | boolean | optional | Make the speaker group list expanded by default.
| show_group_count | boolean | true | Have the number of grouped speakers displayed (if any) in the card name.
| icon | string | optional | Override default group button icon *(any mdi icon)*.

<a name="speaker_foot1"><sup>1</sup></a> Currently not yet supported in Home Assistant, *soon™*
<a name="speaker_foot2"><sup>2</sup></a> Some features are not yet supported.
<a name="speaker_foot2"><sup>2</sup></a> All features are not yet supported.

#### Speaker entity object
| Name | Type | Default | Description |
Expand Down
7 changes: 7 additions & 0 deletions src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ const MEDIA_INFO = [
{ attr: 'app_name' },
];

const PLATFORM = {
SONOS: 'sonos',
SQUEEZEBOX: 'squeezebox',
BLUESOUND: 'bluesound',
SOUNDTOUCH: 'soundtouch',
};

export {
DEFAULT_HIDE,
Expand All @@ -64,4 +70,5 @@ export {
BREAKPOINT,
LABEL_SHORTCUT,
MEDIA_INFO,
PLATFORM,
};
52 changes: 37 additions & 15 deletions src/model.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PROGRESS_PROPS, MEDIA_INFO } from './const';
import { PROGRESS_PROPS, MEDIA_INFO, PLATFORM } from './const';

export default class MediaPlayerObject {
constructor(hass, config, entity) {
Expand Down Expand Up @@ -82,12 +82,20 @@ export default class MediaPlayerObject {
}

get group() {
const groupName = `${this.config.speaker_group.platform}_group`;
return this.attr[groupName] || [];
if (this.platform === PLATFORM.SQUEEZEBOX) {
return this.attr.sync_group || [];
}
return this.attr[`${this.platform}_group`] || [];
}

get platform() {
return this.config.speaker_group.platform;
}

get master() {
return this.group[0] || this.config.entity;
return this.supportsMaster
? this.group[0] || this.config.entity
: this.config.entity;
}

get isMaster() {
Expand Down Expand Up @@ -190,14 +198,18 @@ export default class MediaPlayerObject {
return !(typeof this.attr.volume_level === 'undefined');
}

getAttribute(attribute) {
return this.attr[attribute] || '';
get supportsMaster() {
return this.platform !== PLATFORM.SQUEEZEBOX;
}

get artwork() {
return `url(${this.attr.entity_picture_local ? this.hass.hassUrl(this.picture) : this.picture})`;
}

getAttribute(attribute) {
return this.attr[attribute] || '';
}

toggle(e) {
if (this.config.toggle_power)
return this.callService(e, 'toggle');
Expand Down Expand Up @@ -306,28 +318,38 @@ export default class MediaPlayerObject {
}

handleGroupChange(e, entity, checked) {
const { platform } = this.config.speaker_group;
const { platform } = this;
const options = { entity_id: entity };
if (checked) {
options.master = this.config.entity;
if (platform === 'soundtouch') {
const service = this.isGrouped ? 'ADD_ZONE_SLAVE' : 'CREATE_ZONE';
return this.handleSoundtouch(e, service, entity);
switch (platform) {
case PLATFORM.SOUNDTOUCH:
return this.handleSoundtouch(e, this.isGrouped ? 'ADD_ZONE_SLAVE' : 'CREATE_ZONE', entity);
case PLATFORM.SQUEEZEBOX:
return this.callService(e, 'sync', {
entity_id: this.config.entity,
other_player: entity,
}, PLATFORM.SQUEEZEBOX);
default:
return this.callService(e, 'join', options, platform);
}
this.callService(e, 'join', options, platform);
} else {
if (platform === 'soundtouch') {
return this.handleSoundtouch(e, 'REMOVE_ZONE_SLAVE', entity);
switch (platform) {
case PLATFORM.SOUNDTOUCH:
return this.handleSoundtouch(e, 'REMOVE_ZONE_SLAVE', entity);
case PLATFORM.SQUEEZEBOX:
return this.callService(e, 'unsync', options, PLATFORM.SQUEEZEBOX);
default:
return this.callService(e, 'unjoin', options, platform);
}
this.callService(e, 'unjoin', options, platform);
}
}

handleSoundtouch(e, service, entity) {
return this.callService(e, service, {
master: this.master,
slaves: entity,
}, 'soundtouch', true);
}, PLATFORM.SOUNDTOUCH, true);
}

toggleScript(e, id, data = {}) {
Expand Down