mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Fix current mode not selected in card feature (#21063)
This commit is contained in:
parent
06d82a4925
commit
e8eefaf1d3
@ -1,7 +1,7 @@
|
||||
export const filterModes = (
|
||||
supportedModes: string[] | undefined,
|
||||
selectedModes: string[] | undefined
|
||||
): string[] =>
|
||||
export const filterModes = <T extends string = string>(
|
||||
supportedModes: T[] | undefined,
|
||||
selectedModes: T[] | undefined
|
||||
): T[] =>
|
||||
selectedModes
|
||||
? selectedModes.filter((mode) => (supportedModes || []).includes(mode))
|
||||
: supportedModes || [];
|
||||
|
@ -6,7 +6,6 @@ import { styleMap } from "lit/directives/style-map";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import { stateColorCss } from "../../../common/entity/state_color";
|
||||
import { supportsFeature } from "../../../common/entity/supports-feature";
|
||||
import "../../../components/ha-control-button";
|
||||
import "../../../components/ha-control-button-group";
|
||||
import "../../../components/ha-control-select";
|
||||
@ -70,37 +69,18 @@ class HuiAlarmModeCardFeature
|
||||
}
|
||||
}
|
||||
|
||||
private _modes = memoizeOne(
|
||||
(
|
||||
stateObj: AlarmControlPanelEntity,
|
||||
selectedModes: AlarmMode[] | undefined
|
||||
) => {
|
||||
if (!selectedModes) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return (Object.keys(ALARM_MODES) as AlarmMode[]).filter((mode) => {
|
||||
const feature = ALARM_MODES[mode].feature;
|
||||
return (
|
||||
(!feature || supportsFeature(stateObj, feature)) &&
|
||||
selectedModes.includes(mode)
|
||||
);
|
||||
private _getCurrentMode = memoizeOne((stateObj: AlarmControlPanelEntity) => {
|
||||
const supportedModes = supportedAlarmModes(stateObj);
|
||||
return supportedModes.find((mode) => mode === stateObj.state);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
private _getCurrentMode(stateObj: AlarmControlPanelEntity) {
|
||||
return this._modes(stateObj, this._config?.modes).find(
|
||||
(mode) => mode === stateObj.state
|
||||
);
|
||||
}
|
||||
|
||||
private async _valueChanged(ev: CustomEvent) {
|
||||
if (!this.stateObj) return;
|
||||
const mode = (ev.detail as any).value as AlarmMode;
|
||||
|
||||
if (mode === this.stateObj!.state) return;
|
||||
if (mode === this.stateObj.state) return;
|
||||
|
||||
const oldMode = this._getCurrentMode(this.stateObj!);
|
||||
const oldMode = this._getCurrentMode(this.stateObj);
|
||||
this._currentMode = mode;
|
||||
|
||||
try {
|
||||
@ -153,6 +133,7 @@ class HuiAlarmModeCardFeature
|
||||
</ha-control-button-group>
|
||||
`;
|
||||
}
|
||||
|
||||
return html`
|
||||
<div class="container">
|
||||
<ha-control-select
|
||||
|
Loading…
x
Reference in New Issue
Block a user