Skip to content

Commit

Permalink
Resolve issue in custom-cards#3 where the functional step count was a…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
lizsugar authored and rohankapoorcom committed Aug 16, 2023
1 parent 8bd2152 commit 5104562
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,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);
Expand Down Expand Up @@ -299,7 +299,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 {
Expand Down
2 changes: 1 addition & 1 deletion src/slider-button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5104562

Please sign in to comment.