From b495ac161c795b70d4a432cbf851187ec8a88e09 Mon Sep 17 00:00:00 2001 From: Liz Sugar Date: Fri, 20 May 2022 12:26:46 -0700 Subject: [PATCH] Resolve issue in #3 where the functional step count was a result of both the step and the max of an input_number entity. Appears that at this time applyStep() is unnecessary, and was in fact causing the problem I have tested stepped sliders of both input_number entities as well as light and climate entities, and stepping still works as expected when applyStep() is not called at all. This does not resolve the issue where step count results in "illegal" values on certain input_number entities. --- dist/slider-button-card.js | 9 ++++++--- src/controllers/controller.ts | 7 +++++-- src/slider-button-card.ts | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/dist/slider-button-card.js b/dist/slider-button-card.js index b680350..8a11da0 100644 --- a/dist/slider-button-card.js +++ b/dist/slider-button-card.js @@ -5443,7 +5443,7 @@ class Controller { } moveSlider(event, { left, top, width, height }) { let percentage = this.calcMovementPercentage(event, { left, top, width, height }); - percentage = this.applyStep(percentage); + //percentage = this.applyStep(percentage); percentage = normalize(percentage, 0, 100); if (!this.isValuePercentage) { percentage = percentageToValue(percentage, this.min, this.max); @@ -5476,7 +5476,10 @@ class Controller { return percentage; } applyStep(value) { - return Math.round(value / this.step) * this.step; + this.log("applyStep value", value); + let rounded = Math.round(value / this.step) * this.step; + this.log("applyStep round", rounded); + return rounded; } log(name = '', value = '') { if (this._config.debug) { @@ -7422,7 +7425,7 @@ let SliderButtonCard = class SliderButtonCard extends LitElement { // eslint-disable-next-line @typescript-eslint/camelcase show_state: true, compact: false, // eslint-disable-next-line @typescript-eslint/camelcase - action_button: copy(ActionButtonConfigDefault), debug: false }, config); + action_button: copy(ActionButtonConfigDefault), debug: true }, config); this.ctrl = ControllerFactory.getInstance(this.config); } shouldUpdate(changedProps) { diff --git a/src/controllers/controller.ts b/src/controllers/controller.ts index 9d7a9c0..38156f9 100644 --- a/src/controllers/controller.ts +++ b/src/controllers/controller.ts @@ -235,7 +235,7 @@ export abstract class Controller { moveSlider(event: any, {left, top, width, height}): number { let percentage = this.calcMovementPercentage(event, {left, top, width, height}); - percentage = this.applyStep(percentage); + //percentage = this.applyStep(percentage); percentage = normalize(percentage, 0, 100); if (!this.isValuePercentage) { percentage = percentageToValue(percentage, this.min, this.max); @@ -282,7 +282,10 @@ export abstract class Controller { } applyStep(value: number): number { - return Math.round(value / this.step) * this.step; + this.log("applyStep value", value); + let rounded = Math.round(value / this.step) * this.step; + this.log("applyStep round", rounded); + return rounded; } log(name = '', value: string | number | object = ''): void { diff --git a/src/slider-button-card.ts b/src/slider-button-card.ts index 8ab80ad..780d1dc 100644 --- a/src/slider-button-card.ts +++ b/src/slider-button-card.ts @@ -91,7 +91,7 @@ export class SliderButtonCard extends LitElement implements LovelaceCard { compact: false, // eslint-disable-next-line @typescript-eslint/camelcase action_button: copy(ActionButtonConfigDefault), - debug: false, + debug: true, ...config }; this.ctrl = ControllerFactory.getInstance(this.config);