Skip to content

Commit

Permalink
feature: make it possible to specify which player's volume to control…
Browse files Browse the repository at this point in the history
… in player section
  • Loading branch information
punxaphil committed Apr 11, 2024
1 parent ee9d6f9 commit 8ab43d6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ entitiesToIgnoreVolumeLevelFor: # default is empty. Use this if you want to igno
- media_player.my_sonos_port_device
artworkMinHeight: 10 # default is 5. Use this to change the minimum height of the artwork in the player section. Unit is in rem.
artworkAsBackground: true # default is false. Will show the artwork as background for the player section.
playerVolumeOnlyAffectsMainPlayer: true # default is false. Will only affect the main player when changing volume in the player section.
playerVolumeEntityId: media_player.bedroom # default is empty. Use this to control the volume of another player in the player section. Entity ID must the selected player or part of the selected player's group, otherwise it will not be controlled.

# media browser specific
mediaBrowserItemsPerRow: 1 # default is 4. Use this to show items as list.
Expand Down
10 changes: 6 additions & 4 deletions src/components/player-controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class PlayerControls extends LitElement {
private config!: CardConfig;
private activePlayer!: MediaPlayer;
private mediaControlService!: MediaControlService;
private volumePlayer!: MediaPlayer;

render() {
this.config = this.store.config;
this.activePlayer = this.store.activePlayer;
this.mediaControlService = this.store.mediaControlService;

const noUpDown = !!this.config.showVolumeUpAndDownButtons && nothing;
this.volumePlayer = this.activePlayer.getMember(this.config.playerVolumeEntityId) ?? this.activePlayer;
return html`
<div class="main" id="mediaControls">
${when(
Expand All @@ -40,18 +42,18 @@ class PlayerControls extends LitElement {
</div>
<sonos-volume
.store=${this.store}
.player=${this.activePlayer}
.updateMembers=${!this.config.playerVolumeOnlyAffectsMainPlayer}
.player=${this.volumePlayer}
.updateMembers=${!this.config.playerVolumeEntityId}
></sonos-volume>
`,
)}
</div>
`;
}
private volDown = async () =>
await this.mediaControlService.volumeDown(this.activePlayer, !this.config.playerVolumeOnlyAffectsMainPlayer);
await this.mediaControlService.volumeDown(this.volumePlayer, !this.config.playerVolumeEntityId);
private volUp = async () =>
await this.mediaControlService.volumeUp(this.activePlayer, !this.config.playerVolumeOnlyAffectsMainPlayer);
await this.mediaControlService.volumeUp(this.volumePlayer, !this.config.playerVolumeEntityId);

private async getAudioInputFormat() {
const sensors = await this.store.hassService.getRelatedEntities(this.activePlayer, 'sensor');
Expand Down
4 changes: 2 additions & 2 deletions src/editor/advanced-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export const ADVANCED_SCHEMA = [
selector: { boolean: {} },
},
{
name: 'playerVolumeOnlyAffectsMainPlayer',
selector: { boolean: {} },
name: 'playerVolumeEntityId',
selector: { entity: { multiple: false, filter: { domain: 'media_player' } } },
},
{
name: 'dontSwitchPlayerWhenGrouping',
Expand Down
2 changes: 1 addition & 1 deletion src/model/media-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class MediaPlayer {
this.ignoreVolume = !!this.config.entitiesToIgnoreVolumeLevelFor?.includes(this.volumePlayer.id);
}

getMember(playerId: string) {
getMember(playerId?: string) {
return this.members.find((member) => member.id === playerId);
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface CardConfig extends LovelaceCardConfig {
dynamicVolumeSliderMax?: number;
artworkMinHeight?: number;
artworkAsBackground?: boolean;
playerVolumeOnlyAffectsMainPlayer?: boolean;
playerVolumeEntityId?: string;
dontSwitchPlayerWhenGrouping?: boolean;
}

Expand Down

0 comments on commit 8ab43d6

Please sign in to comment.