From 37cba9283024bbb678b964582722e9a3a647ad7a Mon Sep 17 00:00:00 2001 From: Johan Frick Date: Mon, 11 Mar 2024 08:03:09 +0100 Subject: [PATCH] feature: configurable dynamic volume slider max and threshold --- README.md | 2 ++ src/components/volume.ts | 8 +++++++- src/editor/advanced-editor.ts | 16 ++++++++++++++++ src/types.ts | 2 ++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4178f662..9c285a98 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,8 @@ customSources: # Main use case is probably to set tv media player to play TV sou - title: TV thumbnail: https://cdn-icons-png.flaticon.com/512/716/716429.png dynamicVolumeSlider: true # default is false. See more in section further down. +dynamicVolumeSliderThreshold: 30 # default is 20. Use this to change the threshold for the dynamic volume slider. +dynamicVolumeSliderMax: 40 # default is 30. Use this to change the max value for the dynamic volume slider. artworkHostname: http://192.168.0.59:8123 #default is ''. Usually not needed, but depending on your setup your device might not be able to access the artwork on the default host. One example where it could be needed is if you cast the dashboard with Google Cast. showAudioInputFormat: true # default is false. Will show the audio input format (e.g. Dolby Digital) in the player section if available. By default, it will only show if the input format in the volumes section. fallbackArtwork: https://cdn-icons-png.flaticon.com/512/651/651717.png # Override default fallback artwork image if artwork is missing for the currently selected media. diff --git a/src/components/volume.ts b/src/components/volume.ts index f2b128df..edc41386 100755 --- a/src/components/volume.ts +++ b/src/components/volume.ts @@ -20,7 +20,7 @@ class Volume extends LitElement { this.mediaControlService = this.store.mediaControlService; const volume = this.player.getVolume(); - const max = volume < 20 && this.config.dynamicVolumeSlider ? 30 : 100; + const max = this.getMax(volume); const muteIcon = this.player.isMuted(this.updateMembers) ? mdiVolumeMute : mdiVolumeHigh; const disabled = this.player.ignoreVolume; @@ -44,6 +44,12 @@ class Volume extends LitElement { `; } + private getMax(volume: number) { + const dynamicThreshold = Math.max(0, Math.min(this.config.dynamicVolumeSliderThreshold ?? 20, 100)); + const dynamicMax = Math.max(0, Math.min(this.config.dynamicVolumeSliderMax ?? 30, 100)); + return volume < dynamicThreshold && this.config.dynamicVolumeSlider ? dynamicMax : 100; + } + private async volumeChanged(e: Event) { const newVolume = numberFromEvent(e); return await this.mediaControlService.volumeSet(this.player, newVolume, this.updateMembers); diff --git a/src/editor/advanced-editor.ts b/src/editor/advanced-editor.ts index 59d3089a..5aed033c 100644 --- a/src/editor/advanced-editor.ts +++ b/src/editor/advanced-editor.ts @@ -10,6 +10,22 @@ export const ADVANCED_SCHEMA = [ name: 'dynamicVolumeSlider', selector: { boolean: {} }, }, + { + type: 'integer', + name: 'dynamicVolumeSliderThreshold', + default: 20, + required: true, + valueMin: 1, + valueMax: 100, + }, + { + type: 'integer', + name: 'dynamicVolumeSliderMax', + default: 30, + required: true, + valueMin: 1, + valueMax: 100, + }, { name: 'hideBrowseMediaButton', selector: { boolean: {} }, diff --git a/src/types.ts b/src/types.ts index f4b6a745..954e8c50 100644 --- a/src/types.ts +++ b/src/types.ts @@ -56,6 +56,8 @@ export interface CardConfig extends LovelaceCardConfig { adjustVolumeRelativeToMainPlayer?: boolean; skipApplyButtonWhenGrouping?: boolean; hideVolumeCogwheel?: boolean; + dynamicVolumeSliderThreshold?: number; + dynamicVolumeSliderMax?: number; } export interface MediaArtworkOverride {