Skip to content

Commit

Permalink
Add validation to 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 a86339f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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
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 a86339f

Please sign in to comment.