Skip to content

Commit

Permalink
Add 2024.7 backward compatibility (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Aug 5, 2024
1 parent e2b2953 commit 46bb4ee
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 52 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"start": "rollup -c --watch --bundleConfigAsCjs",
"build": "rollup -c --bundleConfigAsCjs",
"format": "prettier --write .",
"start:hass-stable": "docker run --rm -p8123:8123 -v ${PWD}/.hass_dev:/config homeassistant/home-assistant:stable",
"start:hass-stable-cmd": "docker run --rm -p8123:8123 -v %cd%/.hass_dev:/config homeassistant/home-assistant:stable",
"start:hass": "docker run --rm -p8123:8123 -v ${PWD}/.hass_dev:/config homeassistant/home-assistant:beta",
"start:hass-cmd": "docker run --rm -p8123:8123 -v %cd%/.hass_dev:/config homeassistant/home-assistant:beta",
"start:hass-dev": "docker run --rm -p8123:8123 -v ${PWD}/.hass_dev:/config homeassistant/home-assistant:dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { html, nothing } from "lit";
import { customElement, state } from "lit/decorators.js";
import memoizeOne from "memoize-one";
import { assert } from "superstruct";
import { LocalizeFunc, LovelaceCardEditor, fireEvent } from "../../ha";
import {
LocalizeFunc,
LovelaceCardEditor,
atLeastHaVersion,
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 @@ -37,24 +42,32 @@ const states = [
"armed_custom_bypass",
];

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),
]);
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),
]
);

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

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

return html`
<ha-form
Expand Down
14 changes: 9 additions & 5 deletions src/cards/chips-card/chips/action-chip-editor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { fireEvent, HomeAssistant } from "../../../ha";
import { atLeastHaVersion, 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,6 +10,7 @@ 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 @@ -19,7 +20,7 @@ const actions: UiAction[] = [
"none",
];

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

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

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

return html`
<ha-form
.hass=${this.hass}
.data=${this._config}
.schema=${SCHEMA}
.schema=${schema}
.computeLabel=${this._computeLabel}
@value-changed=${this._valueChanged}
></ha-form>
Expand Down
14 changes: 9 additions & 5 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,6 @@
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { fireEvent, HomeAssistant } from "../../../ha";
import { atLeastHaVersion, 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,6 +10,7 @@ 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 @@ -20,7 +21,7 @@ const actions: UiAction[] = [
"none",
];

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

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

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

return html`
<ha-form
.hass=${this.hass}
.data=${this._config}
.schema=${SCHEMA}
.schema=${schema}
.computeLabel=${this._computeLabel}
@value-changed=${this._valueChanged}
></ha-form>
Expand Down
14 changes: 9 additions & 5 deletions src/cards/chips-card/chips/weather-chip-editor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { fireEvent, HomeAssistant } from "../../../ha";
import { atLeastHaVersion, 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,6 +9,7 @@ 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 @@ -22,7 +23,7 @@ const actions: UiAction[] = [
"none",
];

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

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

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

return html`
<ha-form
.hass=${this.hass}
.data=${this._config}
.schema=${SCHEMA}
.schema=${schema}
.computeLabel=${this._computeLabel}
@value-changed=${this._valueChanged}
></ha-form>
Expand Down
14 changes: 9 additions & 5 deletions src/cards/person-card/person-card-editor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { html, nothing } from "lit";
import { customElement, state } from "lit/decorators.js";
import { assert } from "superstruct";
import { LovelaceCardEditor, fireEvent } from "../../ha";
import { LovelaceCardEditor, atLeastHaVersion, 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,6 +12,7 @@ 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 @@ -22,13 +23,13 @@ const actions: UiAction[] = [
"none",
];

const SCHEMA: HaFormSchema[] = [
const computeSchema = memoizeOne((useCallService: boolean): 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),
];
...computeActionsFormSchema(actions, useCallService),
]);

@customElement(PERSON_CARD_EDITOR_NAME)
export class SwitchCardEditor
Expand Down Expand Up @@ -63,11 +64,14 @@ export class SwitchCardEditor
return nothing;
}

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

return html`
<ha-form
.hass=${this.hass}
.data=${this._config}
.schema=${SCHEMA}
.schema=${schema}
.computeLabel=${this._computeLabel}
@value-changed=${this._valueChanged}
></ha-form>
Expand Down
14 changes: 9 additions & 5 deletions src/cards/select-card/select-card-editor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { html, nothing } from "lit";
import { customElement, state } from "lit/decorators.js";
import { assert } from "superstruct";
import { LovelaceCardEditor, fireEvent } from "../../ha";
import { LovelaceCardEditor, atLeastHaVersion, 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,6 +12,7 @@ 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 @@ -22,7 +23,7 @@ const actions: UiAction[] = [
"none",
];

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

@customElement(SELECT_CARD_EDITOR_NAME)
export class SelectCardEditor
Expand Down Expand Up @@ -74,11 +75,14 @@ export class SelectCardEditor
return nothing;
}

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

return html`
<ha-form
.hass=${this.hass}
.data=${this._config}
.schema=${SCHEMA}
.schema=${schema}
.computeLabel=${this._computeLabel}
@value-changed=${this._valueChanged}
></ha-form>
Expand Down
14 changes: 9 additions & 5 deletions src/cards/update-card/update-card-editor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { html, nothing } from "lit";
import { customElement, state } from "lit/decorators.js";
import { assert } from "superstruct";
import { LovelaceCardEditor, fireEvent } from "../../ha";
import { LovelaceCardEditor, atLeastHaVersion, 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,6 +12,7 @@ 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 @@ -24,7 +25,7 @@ const actions: UiAction[] = [
"none",
];

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

@customElement(UPDATE_CARD_EDITOR_NAME)
export class UpdateCardEditor
Expand Down Expand Up @@ -76,11 +77,14 @@ export class UpdateCardEditor
return nothing;
}

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

return html`
<ha-form
.hass=${this.hass}
.data=${this._config}
.schema=${SCHEMA}
.schema=${schema}
.computeLabel=${this._computeLabel}
@value-changed=${this._valueChanged}
></ha-form>
Expand Down
Loading

0 comments on commit 46bb4ee

Please sign in to comment.