Skip to content

Commit

Permalink
feature: make it possible to adjust volume relative to main player
Browse files Browse the repository at this point in the history
fixes #294
  • Loading branch information
punxaphil committed Feb 8, 2024
1 parent 9397df8 commit 0ce21ba
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ entities: # Entities are automatically discovered if you don't supply this setti
- media_player.sonos_livingroom
excludeItemsInEntitiesList: true # Will invert the selection in the `entities` list, so that all players that are not in the list will be used.
showNonSonosPlayers: true # default is false, which means only Sonos players will be shown.
volumeStepSize: 1 # Use this to change the step size when using volume up/down.. Default is to use the step size of Home Assistant's media player integration.
volumeStepSize: 1 # Use this to change the step size when using volume up/down. Default is to use the step size of Home Assistant's media player integration.
adjustVolumeRelativeToMainPlayer: true # default is false, which means all players will be set to the same volume as the main player. If set to true, volume will be adjusted relative to the main player in the group.

# groups specific
groupsTitle: ''
Expand Down
4 changes: 4 additions & 0 deletions src/editor/advanced-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export const ADVANCED_SCHEMA = [
name: 'showAudioInputFormat',
selector: { boolean: {} },
},
{
name: 'adjustVolumeRelativeToMainPlayer',
selector: { boolean: {} },
},
{
type: 'string',
help: 'Override default fallback artwork image if artwork is missing for the currently selected media',
Expand Down
7 changes: 6 additions & 1 deletion src/services/media-control-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,16 @@ export default class MediaControlService {
}

async volumeSet(mediaPlayer: MediaPlayer, volume: number, updateMembers = true) {
const volume_level = volume / 100;
let volume_level = volume / 100;

await this.hassService.callMediaService('volume_set', { entity_id: mediaPlayer.id, volume_level: volume_level });
const relativeVolumeChange = volume_level - mediaPlayer.attributes.volume_level;
if (updateMembers) {
for (const member of mediaPlayer.members) {
if (this.config.adjustVolumeRelativeToMainPlayer) {
volume_level = member.attributes.volume_level + relativeVolumeChange;
volume_level = Math.min(1, Math.max(0, volume_level));
}
await this.hassService.callMediaService('volume_set', { entity_id: member.id, volume_level });
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface CardConfig extends LovelaceCardConfig {
replaceHttpWithHttpsForThumbnails?: boolean;
volumeStepSize?: number;
mediaBrowserTitle?: string;
adjustVolumeRelativeToMainPlayer?: boolean;
}

export interface MediaArtworkOverride {
Expand Down

0 comments on commit 0ce21ba

Please sign in to comment.