Guard calling input select row with bad option (#12181)

This commit is contained in:
Paulus Schoutsen 2022-03-31 18:32:10 -07:00 committed by GitHub
parent ba8b20d877
commit 419d659311
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ import { computeStateName } from "../../../common/entity/compute_state_name";
import "../../../components/ha-select";
import { UNAVAILABLE } from "../../../data/entity";
import { forwardHaptic } from "../../../data/haptics";
import type { InputSelectEntity } from "../../../data/input_select";
import { SelectEntity, setSelectOption } from "../../../data/select";
import { HomeAssistant } from "../../../types";
import { EntitiesCardEntityConfig } from "../cards/types";
@ -106,9 +107,14 @@ class HuiSelectEntityRow extends LitElement implements LovelaceRow {
}
private _selectedChanged(ev): void {
const stateObj = this.hass!.states[this._config!.entity];
const stateObj = this.hass!.states[
this._config!.entity
] as InputSelectEntity;
const option = ev.target.value;
if (option === stateObj.state) {
if (
option === stateObj.state ||
!stateObj.attributes.options.includes(option)
) {
return;
}