Skip to content

Commit

Permalink
Add step validation to input_number and number selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh committed Mar 23, 2024
1 parent b77839c commit cebe490
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,10 @@ class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {

private _selectedValueChanged(ev: Event): void {
const stateObj = this.hass!.states[this._config!.entity];
const target = ev.target as HTMLInputElement;

if ((ev.target as HTMLInputElement).value !== stateObj.state) {
setValue(
this.hass!,
stateObj.entity_id,
(ev.target as HTMLInputElement).value
);
if (target.value !== stateObj.state && !target.validity.stepMismatch) {
setValue(this.hass!, stateObj.entity_id, target.value);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/panels/lovelace/entity-rows/hui-number-entity-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ class HuiNumberEntityRow extends LitElement implements LovelaceRow {

private _selectedValueChanged(ev): void {
const stateObj = this.hass!.states[this._config!.entity];
const target = ev.target as HTMLInputElement;

if (ev.target.value !== stateObj.state) {
setValue(this.hass!, stateObj.entity_id, ev.target.value!);
if (target.value !== stateObj.state && !target.validity.stepMismatch) {
setValue(this.hass!, stateObj.entity_id, target.value);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/state-summary/state-card-input_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class StateCardInputNumber extends LitElement {
}

private _selectedValueChanged(ev: Event): void {
if ((ev.target as HTMLInputElement).value !== this.stateObj.state) {
const target = ev.target as HTMLInputElement;
if (target.value !== this.stateObj.state && !target.validity.stepMismatch) {
setValue(
this.hass!,
this.stateObj.entity_id,
Expand Down
5 changes: 3 additions & 2 deletions src/state-summary/state-card-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ class StateCardNumber extends LitElement {
}

private async _selectedValueChanged(ev: Event) {
const value = (ev.target as HTMLInputElement).value;
if (value === this.stateObj.state) {
const target = ev.target as HTMLInputElement;
const value = target.value;
if (value === this.stateObj.state || target.validity.stepMismatch) {
return;
}
await this.hass.callService("number", "set_value", {
Expand Down

0 comments on commit cebe490

Please sign in to comment.