Skip to content

Commit

Permalink
Bug Fix: my-slider-v2 cover entity - value shown incorrect when using…
Browse files Browse the repository at this point in the history
… sliderMin config key.
  • Loading branch information
AnthonMS committed Oct 27, 2024
1 parent aea9aca commit 535b281
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 253 deletions.
6 changes: 3 additions & 3 deletions dist/dev/my-cards.js

Large diffs are not rendered by default.

195 changes: 120 additions & 75 deletions dist/my-button.js

Large diffs are not rendered by default.

339 changes: 192 additions & 147 deletions dist/my-cards.js

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions dist/my-slider-v2.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/my-slider.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/cards/extras/const.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const CARD_VERSION = '2.0.4'
export const SLIDER_VERSION = '3.0.6'
export const SLIDER_VERSION = '3.0.7'
export const BUTTON_VERSION = '1.0.2'


Expand Down
25 changes: 16 additions & 9 deletions src/cards/my-slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ export class MySliderV2 extends LitElement {
private sliderVal: number = 0
private sliderValPercent: number = 0.00
private initialTransition: string = ''
private setSliderValues(val, valPercent): void {
if (this._config.inverse) {
this.sliderVal = this._config.max - val
this.sliderValPercent = 100 - valPercent
}
else {
this.sliderVal = val
this.sliderValPercent = valPercent
private setSliderValues(val, valPercent, alreadyInversed = false): void {
if (this._config.inverse && !alreadyInversed) {
this.sliderVal = this._config.max - val;
this.sliderValPercent = 100 - valPercent;
} else {
this.sliderVal = val;
this.sliderValPercent = valPercent;
}
}

Expand Down Expand Up @@ -393,6 +392,7 @@ export class MySliderV2 extends LitElement {
let tmpVal = 0
let sliderVal1 = 0
let sliderVal2 = 0
let alreadyInversed = false
switch (entityType) {

case 'light': /* ------------ LIGHT ------------ */
Expand Down Expand Up @@ -528,6 +528,13 @@ export class MySliderV2 extends LitElement {
defaultConfig.max = defaultConfig.max - defaultConfig.min
tmpVal = tmpVal - defaultConfig.min
}

// Calculate tmpVal based on the inverse logic
if (defaultConfig.inverse) {
// Inverted logic
tmpVal = defaultConfig.max - tmpVal; // Invert for the slider
alreadyInversed = true
}

tmpVal = (tmpVal * (100 - defaultConfig.sliderMin) / 100) + defaultConfig.sliderMin
tmpVal = tmpVal < defaultConfig.sliderMin ? defaultConfig.sliderMin : tmpVal
Expand Down Expand Up @@ -587,7 +594,7 @@ export class MySliderV2 extends LitElement {
}

this._config = deepMerge(defaultConfig, this._config)
this.setSliderValues(sliderVal1, sliderVal2)
this.setSliderValues(sliderVal1, sliderVal2, alreadyInversed)

if (defaultConfig.mode === 'seekbar' && this.entity.state === 'playing') {
this.updateSeekbar()
Expand Down

0 comments on commit 535b281

Please sign in to comment.