Skip to content

Commit

Permalink
Resolve issue in mattieha#3 where the functional step count was a res…
Browse files Browse the repository at this point in the history
…ult 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 committed May 20, 2022
1 parent a1050f0 commit b495ac1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions dist/slider-button-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
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 b495ac1

Please sign in to comment.