Skip to content

Commit

Permalink
Allow to add name in heading entity badge state content (#22161)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Sep 30, 2024
1 parent b6efedf commit 175f68e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const DEFAULT_CONFIG: Partial<EntityHeadingBadgeConfig> = {
const entityConfigStruct = object({
type: optional(string()),
entity: string(),
name: optional(string()),
icon: optional(string()),
state_content: optional(union([string(), array(string())])),
show_state: optional(boolean()),
Expand Down Expand Up @@ -86,6 +87,12 @@ export class HuiHeadingEntityEditor
name: "",
type: "grid",
schema: [
{
name: "name",
selector: {
text: {},
},
},
{
name: "icon",
selector: { icon: {} },
Expand Down Expand Up @@ -128,7 +135,7 @@ export class HuiHeadingEntityEditor
},
{
name: "state_content",
selector: { ui_state_content: {} },
selector: { ui_state_content: { allow_name: true } },
context: { filter_entity: "entity" },
},
],
Expand Down Expand Up @@ -269,6 +276,10 @@ export class HuiHeadingEntityEditor
return this.hass!.localize(
`ui.panel.lovelace.editor.card.heading.entity_config.${schema.name}_helper`
);
case "name":
return this.hass!.localize(
`ui.panel.lovelace.editor.card.heading.entity_config.name_helper`
);
default:
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,15 @@ export class HuiEntityHeadingBadge
"--icon-color": color,
};

const name = config.name || stateObj.attributes.friendly_name;

return html`
<ha-heading-badge
.type=${hasAction(config.tap_action) ? "button" : "text"}
@action=${this._handleAction}
.actionHandler=${actionHandler()}
style=${styleMap(style)}
.title=${name}
>
${config.show_icon
? html`
Expand All @@ -148,6 +151,7 @@ export class HuiEntityHeadingBadge
.hass=${this.hass}
.stateObj=${stateObj}
.content=${config.state_content}
.name=${config.name}
></state-display>
`
: nothing}
Expand Down
1 change: 1 addition & 0 deletions src/panels/lovelace/heading-badges/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ErrorBadgeConfig extends LovelaceHeadingBadgeConfig {
export interface EntityHeadingBadgeConfig extends LovelaceHeadingBadgeConfig {
type?: "entity";
entity: string;
name?: string;
state_content?: string | string[];
icon?: string;
show_state?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6026,6 +6026,8 @@
"entity_config": {
"color": "[%key:ui::panel::lovelace::editor::card::tile::color%]",
"color_helper": "[%key:ui::panel::lovelace::editor::card::tile::color_helper%]",
"name": "[%key:ui::panel::lovelace::editor::card::generic::name%]",
"name_helper": "Visible if selected in state content",
"visibility": "Visibility",
"visibility_explanation": "The entity will be shown when ALL conditions below are fulfilled. If no conditions are set, the entity will always be shown.",
"appearance": "Appearance",
Expand Down

0 comments on commit 175f68e

Please sign in to comment.