Skip to content

Commit

Permalink
Rename support for string entity
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Sep 26, 2024
1 parent 89b0d84 commit 3943c63
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
10 changes: 2 additions & 8 deletions src/panels/lovelace/cards/hui-heading-card.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import memoizeOne from "memoize-one";
import "../../../components/ha-card";
import "../../../components/ha-icon";
import "../../../components/ha-icon-next";
Expand All @@ -12,7 +11,6 @@ import { HomeAssistant } from "../../../types";
import { actionHandler } from "../common/directives/action-handler-directive";
import { handleAction } from "../common/handle-action";
import { hasAction } from "../common/has-action";
import { processEditorEntities } from "../editor/process-editor-entities";
import "../heading-items/hui-heading-item";
import type {
LovelaceCard,
Expand Down Expand Up @@ -77,10 +75,6 @@ export class HuiHeadingCard extends LitElement implements LovelaceCard {
handleAction(this, this.hass!, this._config!, ev.detail.action!);
}

private _items = memoizeOne((items: HeadingCardConfig["items"]) =>
processEditorEntities(items || [])
);

protected render() {
if (!this._config || !this.hass) {
return nothing;
Expand All @@ -90,7 +84,7 @@ export class HuiHeadingCard extends LitElement implements LovelaceCard {

const style = this._config.heading_style || "title";

const items = this._items(this._config.items);
const items = this._config.items;

return html`
<ha-card>
Expand All @@ -110,7 +104,7 @@ export class HuiHeadingCard extends LitElement implements LovelaceCard {
: nothing}
${actionable ? html`<ha-icon-next></ha-icon-next>` : nothing}
</div>
${items.length
${items?.length
? html`
<div class="items">
${items.map(
Expand Down
6 changes: 3 additions & 3 deletions src/panels/lovelace/cards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ export interface HeadingCardConfig extends LovelaceCardConfig {
heading?: string;
icon?: string;
tap_action?: ActionConfig;
items?: (LovelaceHeadingItemConfig | string)[];
/** @deprecated Use `triggers` instead */
entities?: (LovelaceHeadingItemConfig | string)[];
items?: LovelaceHeadingItemConfig[];
/** @deprecated Use `items` instead */
entities?: LovelaceHeadingItemConfig[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ import type {
} from "../../../../components/ha-form/types";
import "../../../../components/ha-svg-icon";
import type { HomeAssistant } from "../../../../types";
import { migrateHeadingCardConfig } from "../../cards/hui-heading-card";
import type { HeadingCardConfig } from "../../cards/types";
import { UiAction } from "../../components/hui-action-editor";
import {
EntityHeadingItemConfig,
LovelaceHeadingItemConfig,
} from "../../heading-items/types";
import type { LovelaceCardEditor } from "../../types";
import { processEditorEntities } from "../process-editor-entities";
import { actionConfigStruct } from "../structs/action-struct";
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
import { EditSubElementEvent } from "../types";
import { configElementStyle } from "./config-elements-style";
import "./hui-heading-items-editor";
import { migrateHeadingCardConfig } from "../../cards/hui-heading-card";

const actions: UiAction[] = ["navigate", "url", "perform-action", "none"];

Expand Down Expand Up @@ -112,7 +111,7 @@ export class HuiHeadingCardEditor

private _items = memoizeOne(
(items: HeadingCardConfig["items"]): LovelaceHeadingItemConfig[] =>
processEditorEntities(items || [])
items || []
);

protected render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import "../../../../components/ha-svg-icon";
import { HomeAssistant } from "../../../../types";
import { LovelaceHeadingItemConfig } from "../../heading-items/types";

type EntityConfig = {
entity: string;
};

declare global {
interface HASSDomEvents {
"edit-heading-item": { index: number };
Expand Down Expand Up @@ -193,7 +189,10 @@ export class HuiHeadingItemsEditor extends LitElement {
if (!ev.detail.value) {
return;
}
const newEntity: EntityConfig = { entity: ev.detail.value };
const newEntity: LovelaceHeadingItemConfig = {
type: "entity",
entity: ev.detail.value,
};
const newItems = (this.items || []).concat(newEntity);
fireEvent(this, "heading-items-changed", { items: newItems });
}
Expand Down

0 comments on commit 3943c63

Please sign in to comment.