mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 16:56:35 +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 = (
|
export const filterModes = <T extends string = string>(
|
||||||
supportedModes: string[] | undefined,
|
supportedModes: T[] | undefined,
|
||||||
selectedModes: string[] | undefined
|
selectedModes: T[] | undefined
|
||||||
): string[] =>
|
): T[] =>
|
||||||
selectedModes
|
selectedModes
|
||||||
? selectedModes.filter((mode) => (supportedModes || []).includes(mode))
|
? selectedModes.filter((mode) => (supportedModes || []).includes(mode))
|
||||||
: supportedModes || [];
|
: supportedModes || [];
|
||||||
|
@ -6,7 +6,6 @@ import { styleMap } from "lit/directives/style-map";
|
|||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||||
import { stateColorCss } from "../../../common/entity/state_color";
|
import { stateColorCss } from "../../../common/entity/state_color";
|
||||||
import { supportsFeature } from "../../../common/entity/supports-feature";
|
|
||||||
import "../../../components/ha-control-button";
|
import "../../../components/ha-control-button";
|
||||||
import "../../../components/ha-control-button-group";
|
import "../../../components/ha-control-button-group";
|
||||||
import "../../../components/ha-control-select";
|
import "../../../components/ha-control-select";
|
||||||
@ -70,37 +69,18 @@ class HuiAlarmModeCardFeature
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _modes = memoizeOne(
|
private _getCurrentMode = memoizeOne((stateObj: AlarmControlPanelEntity) => {
|
||||||
(
|
const supportedModes = supportedAlarmModes(stateObj);
|
||||||
stateObj: AlarmControlPanelEntity,
|
return supportedModes.find((mode) => mode === stateObj.state);
|
||||||
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(stateObj: AlarmControlPanelEntity) {
|
|
||||||
return this._modes(stateObj, this._config?.modes).find(
|
|
||||||
(mode) => mode === stateObj.state
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _valueChanged(ev: CustomEvent) {
|
private async _valueChanged(ev: CustomEvent) {
|
||||||
|
if (!this.stateObj) return;
|
||||||
const mode = (ev.detail as any).value as AlarmMode;
|
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;
|
this._currentMode = mode;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -153,6 +133,7 @@ class HuiAlarmModeCardFeature
|
|||||||
</ha-control-button-group>
|
</ha-control-button-group>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<ha-control-select
|
<ha-control-select
|
||||||
|
Loading…
x
Reference in New Issue
Block a user