Skip to content

Commit

Permalink
Bump min version to 2024.8
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Feb 28, 2025
1 parent fea08b4 commit f888613
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { html, nothing } from "lit";
import { customElement, state } from "lit/decorators.js";
import memoizeOne from "memoize-one";
import { assert } from "superstruct";
import {
LocalizeFunc,
LovelaceCardEditor,
atLeastHaVersion,
fireEvent,
} from "../../ha";
import { LocalizeFunc, LovelaceCardEditor, fireEvent } from "../../ha";
import setupCustomlocalize from "../../localize";
import { computeActionsFormSchema } from "../../shared/config/actions-config";
import { APPEARANCE_FORM_SCHEMA } from "../../shared/config/appearance-config";
Expand Down Expand Up @@ -42,32 +37,28 @@ const states = [
"armed_custom_bypass",
];

const computeSchema = memoizeOne(
(localize: LocalizeFunc, useCallService: boolean): HaFormSchema[] => [
{
name: "entity",
selector: { entity: { domain: ALARM_CONTROl_PANEL_ENTITY_DOMAINS } },
},
{ name: "name", selector: { text: {} } },
{
name: "icon",
selector: { icon: {} },
context: { icon_entity: "entity" },
},
...APPEARANCE_FORM_SCHEMA,
{
type: "multi_select",
name: "states",
options: states.map((state) => [
state,
localize(
`ui.card.alarm_control_panel.${state.replace("armed", "arm")}`
),
]) as [string, string][],
},
...computeActionsFormSchema(actions, useCallService),
]
);
const computeSchema = memoizeOne((localize: LocalizeFunc): HaFormSchema[] => [
{
name: "entity",
selector: { entity: { domain: ALARM_CONTROl_PANEL_ENTITY_DOMAINS } },
},
{ name: "name", selector: { text: {} } },
{
name: "icon",
selector: { icon: {} },
context: { icon_entity: "entity" },
},
...APPEARANCE_FORM_SCHEMA,
{
type: "multi_select",
name: "states",
options: states.map((state) => [
state,
localize(`ui.card.alarm_control_panel.${state.replace("armed", "arm")}`),
]) as [string, string][],
},
...computeActionsFormSchema(actions),
]);

@customElement(ALARM_CONTROl_PANEL_CARD_EDITOR_NAME)
export class SwitchCardEditor
Expand All @@ -91,8 +82,7 @@ export class SwitchCardEditor
return nothing;
}

const useCallService = !atLeastHaVersion(this.hass.config.version, 2024, 8);
const schema = computeSchema(this.hass!.localize, useCallService);
const schema = computeSchema(this.hass!.localize);

return html`
<ha-form
Expand Down
11 changes: 5 additions & 6 deletions src/cards/chips-card/chips/action-chip-editor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { atLeastHaVersion, fireEvent, HomeAssistant } from "../../../ha";
import memoizeOne from "memoize-one";
import { fireEvent, HomeAssistant } from "../../../ha";
import setupCustomlocalize from "../../../localize";
import { computeActionsFormSchema } from "../../../shared/config/actions-config";
import { GENERIC_LABELS } from "../../../utils/form/generic-fields";
Expand All @@ -10,7 +11,6 @@ import { computeChipEditorComponentName } from "../../../utils/lovelace/chip/chi
import { ActionChipConfig } from "../../../utils/lovelace/chip/types";
import { LovelaceChipEditor } from "../../../utils/lovelace/types";
import { DEFAULT_ACTION_ICON } from "./action-chip";
import memoizeOne from "memoize-one";

const actions: UiAction[] = [
"navigate",
Expand All @@ -20,7 +20,7 @@ const actions: UiAction[] = [
"none",
];

const computeSchema = memoizeOne((useCallService: boolean): HaFormSchema[] => [
const computeSchema = memoizeOne((): HaFormSchema[] => [
{
type: "grid",
name: "",
Expand All @@ -32,7 +32,7 @@ const computeSchema = memoizeOne((useCallService: boolean): HaFormSchema[] => [
{ name: "icon_color", selector: { mush_color: {} } },
],
},
...computeActionsFormSchema(actions, useCallService),
...computeActionsFormSchema(actions),
]);

@customElement(computeChipEditorComponentName("action"))
Expand Down Expand Up @@ -61,8 +61,7 @@ export class EntityChipEditor extends LitElement implements LovelaceChipEditor {
return nothing;
}

const useCallService = !atLeastHaVersion(this.hass.config.version, 2024, 8);
const schema = computeSchema(useCallService);
const schema = computeSchema();

return html`
<ha-form
Expand Down
11 changes: 5 additions & 6 deletions src/cards/chips-card/chips/alarm-control-panel-chip-editor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { atLeastHaVersion, fireEvent, HomeAssistant } from "../../../ha";
import memoizeOne from "memoize-one";
import { fireEvent, HomeAssistant } from "../../../ha";
import setupCustomlocalize from "../../../localize";
import { computeActionsFormSchema } from "../../../shared/config/actions-config";
import { GENERIC_LABELS } from "../../../utils/form/generic-fields";
Expand All @@ -10,7 +11,6 @@ import { computeChipEditorComponentName } from "../../../utils/lovelace/chip/chi
import { AlarmControlPanelChipConfig } from "../../../utils/lovelace/chip/types";
import { LovelaceChipEditor } from "../../../utils/lovelace/types";
import { ALARM_CONTROl_PANEL_ENTITY_DOMAINS } from "../../alarm-control-panel-card/const";
import memoizeOne from "memoize-one";

const actions: UiAction[] = [
"more-info",
Expand All @@ -21,7 +21,7 @@ const actions: UiAction[] = [
"none",
];

const computeSchema = memoizeOne((useCallService: boolean): HaFormSchema[] => [
const computeSchema = memoizeOne((): HaFormSchema[] => [
{
name: "entity",
selector: { entity: { domain: ALARM_CONTROl_PANEL_ENTITY_DOMAINS } },
Expand All @@ -35,7 +35,7 @@ const computeSchema = memoizeOne((useCallService: boolean): HaFormSchema[] => [
],
},
{ name: "icon", selector: { icon: {} }, context: { icon_entity: "entity" } },
...computeActionsFormSchema(actions, useCallService),
...computeActionsFormSchema(actions),
]);

@customElement(computeChipEditorComponentName("alarm-control-panel"))
Expand Down Expand Up @@ -67,8 +67,7 @@ export class AlarmControlPanelChipEditor
return nothing;
}

const useCallService = !atLeastHaVersion(this.hass.config.version, 2024, 8);
const schema = computeSchema(useCallService);
const schema = computeSchema();

return html`
<ha-form
Expand Down
11 changes: 5 additions & 6 deletions src/cards/chips-card/chips/weather-chip-editor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { atLeastHaVersion, fireEvent, HomeAssistant } from "../../../ha";
import memoizeOne from "memoize-one";
import { fireEvent, HomeAssistant } from "../../../ha";
import setupCustomlocalize from "../../../localize";
import { computeActionsFormSchema } from "../../../shared/config/actions-config";
import { GENERIC_LABELS } from "../../../utils/form/generic-fields";
Expand All @@ -9,7 +10,6 @@ import { UiAction } from "../../../utils/form/ha-selector";
import { computeChipEditorComponentName } from "../../../utils/lovelace/chip/chip-element";
import { WeatherChipConfig } from "../../../utils/lovelace/chip/types";
import { LovelaceChipEditor } from "../../../utils/lovelace/types";
import memoizeOne from "memoize-one";

const WEATHER_ENTITY_DOMAINS = ["weather"];
const WEATHER_LABELS = ["show_conditions", "show_temperature"];
Expand All @@ -23,7 +23,7 @@ const actions: UiAction[] = [
"none",
];

const computeSchema = memoizeOne((useCallService: boolean): HaFormSchema[] => [
const computeSchema = memoizeOne((): HaFormSchema[] => [
{ name: "entity", selector: { entity: { domain: WEATHER_ENTITY_DOMAINS } } },
{
type: "grid",
Expand All @@ -33,7 +33,7 @@ const computeSchema = memoizeOne((useCallService: boolean): HaFormSchema[] => [
{ name: "show_temperature", selector: { boolean: {} } },
],
},
...computeActionsFormSchema(actions, useCallService),
...computeActionsFormSchema(actions),
]);

@customElement(computeChipEditorComponentName("weather"))
Expand Down Expand Up @@ -68,8 +68,7 @@ export class WeatherChipEditor
return nothing;
}

const useCallService = !atLeastHaVersion(this.hass.config.version, 2024, 8);
const schema = computeSchema(useCallService);
const schema = computeSchema();

return html`
<ha-form
Expand Down
11 changes: 5 additions & 6 deletions src/cards/person-card/person-card-editor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { html, nothing } from "lit";
import { customElement, state } from "lit/decorators.js";
import memoizeOne from "memoize-one";
import { assert } from "superstruct";
import { LovelaceCardEditor, atLeastHaVersion, fireEvent } from "../../ha";
import { LovelaceCardEditor, fireEvent } from "../../ha";
import setupCustomlocalize from "../../localize";
import { computeActionsFormSchema } from "../../shared/config/actions-config";
import { APPEARANCE_FORM_SCHEMA } from "../../shared/config/appearance-config";
Expand All @@ -12,7 +13,6 @@ import { UiAction } from "../../utils/form/ha-selector";
import { loadHaComponents } from "../../utils/loader";
import { PERSON_CARD_EDITOR_NAME, PERSON_ENTITY_DOMAINS } from "./const";
import { PersonCardConfig, personCardConfigStruct } from "./person-card-config";
import memoizeOne from "memoize-one";

const actions: UiAction[] = [
"more-info",
Expand All @@ -23,12 +23,12 @@ const actions: UiAction[] = [
"none",
];

const computeSchema = memoizeOne((useCallService: boolean): HaFormSchema[] => [
const computeSchema = memoizeOne((): HaFormSchema[] => [
{ name: "entity", selector: { entity: { domain: PERSON_ENTITY_DOMAINS } } },
{ name: "name", selector: { text: {} } },
{ name: "icon", selector: { icon: {} }, context: { icon_entity: "entity" } },
...APPEARANCE_FORM_SCHEMA,
...computeActionsFormSchema(actions, useCallService),
...computeActionsFormSchema(actions),
]);

@customElement(PERSON_CARD_EDITOR_NAME)
Expand Down Expand Up @@ -64,8 +64,7 @@ export class SwitchCardEditor
return nothing;
}

const useCallService = !atLeastHaVersion(this.hass.config.version, 2024, 8);
const schema = computeSchema(useCallService);
const schema = computeSchema();

return html`
<ha-form
Expand Down
11 changes: 5 additions & 6 deletions src/cards/select-card/select-card-editor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { html, nothing } from "lit";
import { customElement, state } from "lit/decorators.js";
import memoizeOne from "memoize-one";
import { assert } from "superstruct";
import { LovelaceCardEditor, atLeastHaVersion, fireEvent } from "../../ha";
import { LovelaceCardEditor, fireEvent } from "../../ha";
import setupCustomlocalize from "../../localize";
import { computeActionsFormSchema } from "../../shared/config/actions-config";
import { APPEARANCE_FORM_SCHEMA } from "../../shared/config/appearance-config";
Expand All @@ -12,7 +13,6 @@ import { UiAction } from "../../utils/form/ha-selector";
import { loadHaComponents } from "../../utils/loader";
import { SELECT_CARD_EDITOR_NAME, SELECT_ENTITY_DOMAINS } from "./const";
import { SelectCardConfig, selectCardConfigStruct } from "./select-card-config";
import memoizeOne from "memoize-one";

const actions: UiAction[] = [
"more-info",
Expand All @@ -23,7 +23,7 @@ const actions: UiAction[] = [
"none",
];

const computeSchema = memoizeOne((useCallService: boolean): HaFormSchema[] => [
const computeSchema = memoizeOne((): HaFormSchema[] => [
{ name: "entity", selector: { entity: { domain: SELECT_ENTITY_DOMAINS } } },
{ name: "name", selector: { text: {} } },
{
Expand All @@ -39,7 +39,7 @@ const computeSchema = memoizeOne((useCallService: boolean): HaFormSchema[] => [
],
},
...APPEARANCE_FORM_SCHEMA,
...computeActionsFormSchema(actions, useCallService),
...computeActionsFormSchema(actions),
]);

@customElement(SELECT_CARD_EDITOR_NAME)
Expand Down Expand Up @@ -75,8 +75,7 @@ export class SelectCardEditor
return nothing;
}

const useCallService = !atLeastHaVersion(this.hass.config.version, 2024, 8);
const schema = computeSchema(useCallService);
const schema = computeSchema();

return html`
<ha-form
Expand Down
11 changes: 5 additions & 6 deletions src/cards/update-card/update-card-editor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { html, nothing } from "lit";
import { customElement, state } from "lit/decorators.js";
import memoizeOne from "memoize-one";
import { assert } from "superstruct";
import { LovelaceCardEditor, atLeastHaVersion, fireEvent } from "../../ha";
import { LovelaceCardEditor, fireEvent } from "../../ha";
import setupCustomlocalize from "../../localize";
import { computeActionsFormSchema } from "../../shared/config/actions-config";
import { APPEARANCE_FORM_SCHEMA } from "../../shared/config/appearance-config";
Expand All @@ -12,7 +13,6 @@ import { UiAction } from "../../utils/form/ha-selector";
import { loadHaComponents } from "../../utils/loader";
import { UPDATE_CARD_EDITOR_NAME, UPDATE_ENTITY_DOMAINS } from "./const";
import { UpdateCardConfig, updateCardConfigStruct } from "./update-card-config";
import memoizeOne from "memoize-one";

const UPDATE_LABELS = ["show_buttons_control"];

Expand All @@ -25,7 +25,7 @@ const actions: UiAction[] = [
"none",
];

const computeSchema = memoizeOne((useCallService: boolean): HaFormSchema[] => [
const computeSchema = memoizeOne((): HaFormSchema[] => [
{ name: "entity", selector: { entity: { domain: UPDATE_ENTITY_DOMAINS } } },
{ name: "name", selector: { text: {} } },
{ name: "icon", selector: { icon: {} }, context: { icon_entity: "entity" } },
Expand All @@ -38,7 +38,7 @@ const computeSchema = memoizeOne((useCallService: boolean): HaFormSchema[] => [
{ name: "collapsible_controls", selector: { boolean: {} } },
],
},
...computeActionsFormSchema(actions, useCallService),
...computeActionsFormSchema(actions),
]);

@customElement(UPDATE_CARD_EDITOR_NAME)
Expand Down Expand Up @@ -77,8 +77,7 @@ export class UpdateCardEditor
return nothing;
}

const useCallService = !atLeastHaVersion(this.hass.config.version, 2024, 8);
const schema = computeSchema(useCallService);
const schema = computeSchema();

return html`
<ha-form
Expand Down
11 changes: 1 addition & 10 deletions src/shared/config/actions-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,8 @@ export type ActionsSharedConfig = {
};

export const computeActionsFormSchema = (
actions?: UiAction[],
useCallService?: boolean
actions?: UiAction[]
): HaFormSchema[] => {
if (useCallService && actions) {
actions = actions.map((action) => {
if (action === "perform-action") {
return "call-service";
}
return action;
});
}
return [
{
name: "tap_action",
Expand Down
Loading

0 comments on commit f888613

Please sign in to comment.