Skip to content

Commit

Permalink
number | remove obsolete numDecimalPlaces (esphome#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
RFDarter authored Apr 18, 2024
1 parent 60e7a92 commit beec790
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
22 changes: 8 additions & 14 deletions packages/v3/src/esp-entity-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ interface entityConfig {
target_temperature_high?: number;
min_temp?: number;
max_temp?: number;
min_value?: number;
max_value?: number;
min_value?: string;
max_value?: string;
step?: number;
min_length?: number;
max_length?: number;
Expand Down Expand Up @@ -337,28 +337,22 @@ class ActionRenderer {
entity: entityConfig,
action: string,
opt: string,
value: number | string,
min?: number,
max?: number,
value: string | number,
min?: string | undefined,
max?: string | undefined,
step = 1
) {
if(entity.mode == 1) {
const val = Number(value);
let stepString = step.toString();
let numDecimalPlaces = 0
if (stepString.indexOf('.') !== -1) {
numDecimalPlaces = stepString.split('.')[1].length;
}
return html`<div class="range">
<label>${min || 0}</label>
<input
type="${entity.mode == 1 ? "number" : "range"}"
name="${entity.unique_id}"
id="${entity.unique_id}"
step="${step}"
min="${min || Math.min(0, val)}"
max="${max || Math.max(10, val)}"
.value="${(val.toFixed(numDecimalPlaces))}"
min="${min || Math.min(0, value as number)}"
max="${max || Math.max(10, value as number)}"
.value="${value}"
@change="${(e: Event) => {
const val = (<HTMLTextAreaElement>e.target)?.value;
this.actioner?.restAction(entity, `${action}?${opt}=${val}`);
Expand Down
19 changes: 6 additions & 13 deletions packages/v3/src/esp-range-slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ export class EspRangeSlider extends LitElement {
private inputRange: HTMLInputElement | null = null;
private currentValue: HTMLInputElement | null = null;

private numDecimalPlaces: number = 0;
private longPressTimer: ReturnType<typeof setTimeout> | null = null;
private isPopupInputVisible: boolean = false;

@property({ type: Number }) value = 0;
@property({ type: Number }) min = 0;
@property({ type: Number }) max = 0;
@property({ type: Number }) step = 0;
@property({ type: String }) value = 0;
@property({ type: String }) min = 0;
@property({ type: String }) max = 0;
@property({ type: String }) step = 0;
@property({ type: String }) name = "";

protected firstUpdated(
Expand All @@ -31,12 +30,6 @@ export class EspRangeSlider extends LitElement {
this.currentValue = this.shadowRoot?.getElementById(
currentValueID
) as HTMLInputElement;

let stepString = this.step.toString();
if (stepString.indexOf('.') !== -1) {
this.numDecimalPlaces = stepString.split('.')[1].length;
}

document.addEventListener('mousedown', (event) => {
if(!document.querySelector('.popup-number-input')) {
return;
Expand Down Expand Up @@ -133,7 +126,7 @@ export class EspRangeSlider extends LitElement {
updateCurrentValueOverlay(): void {
const newValueAsPercent = Number( (this.inputRange.value - this.inputRange.min) * 100 / (this.inputRange.max - this.inputRange.min) ),
newPosition = 10 - (newValueAsPercent * 0.2);
this.currentValue.innerHTML = `<span>${Number(this.inputRange?.value).toFixed(this.numDecimalPlaces)}</span>`;
this.currentValue.innerHTML = `<span>${this.inputRange?.value}</span>`;
this.currentValue.style.left = `calc(${newValueAsPercent}% + (${newPosition}px))`;

const spanTooltip = this.currentValue?.querySelector('span');
Expand Down Expand Up @@ -178,7 +171,7 @@ export class EspRangeSlider extends LitElement {
step="${this.step}"
min="${this.min || Math.min(0, this.value)}"
max="${this.max || Math.max(10, this.value)}"
.value="${(this.value.toFixed(this.numDecimalPlaces))}"
.value="${this.value}"
@input="${this.onInputEvent}"
@change="${this.onInputChangeEvent}"
/>
Expand Down

0 comments on commit beec790

Please sign in to comment.