Allow to add name in heading entity badge state content (#22161)

This commit is contained in:
Paul Bottein 2024-09-30 11:07:25 +02:00 committed by GitHub
parent b6efedfc8d
commit 175f68e0cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 1 deletions

View File

@ -37,6 +37,7 @@ export const DEFAULT_CONFIG: Partial<EntityHeadingBadgeConfig> = {
const entityConfigStruct = object({ const entityConfigStruct = object({
type: optional(string()), type: optional(string()),
entity: string(), entity: string(),
name: optional(string()),
icon: optional(string()), icon: optional(string()),
state_content: optional(union([string(), array(string())])), state_content: optional(union([string(), array(string())])),
show_state: optional(boolean()), show_state: optional(boolean()),
@ -86,6 +87,12 @@ export class HuiHeadingEntityEditor
name: "", name: "",
type: "grid", type: "grid",
schema: [ schema: [
{
name: "name",
selector: {
text: {},
},
},
{ {
name: "icon", name: "icon",
selector: { icon: {} }, selector: { icon: {} },
@ -128,7 +135,7 @@ export class HuiHeadingEntityEditor
}, },
{ {
name: "state_content", name: "state_content",
selector: { ui_state_content: {} }, selector: { ui_state_content: { allow_name: true } },
context: { filter_entity: "entity" }, context: { filter_entity: "entity" },
}, },
], ],
@ -269,6 +276,10 @@ export class HuiHeadingEntityEditor
return this.hass!.localize( return this.hass!.localize(
`ui.panel.lovelace.editor.card.heading.entity_config.${schema.name}_helper` `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: default:
return undefined; return undefined;
} }

View File

@ -125,12 +125,15 @@ export class HuiEntityHeadingBadge
"--icon-color": color, "--icon-color": color,
}; };
const name = config.name || stateObj.attributes.friendly_name;
return html` return html`
<ha-heading-badge <ha-heading-badge
.type=${hasAction(config.tap_action) ? "button" : "text"} .type=${hasAction(config.tap_action) ? "button" : "text"}
@action=${this._handleAction} @action=${this._handleAction}
.actionHandler=${actionHandler()} .actionHandler=${actionHandler()}
style=${styleMap(style)} style=${styleMap(style)}
.title=${name}
> >
${config.show_icon ${config.show_icon
? html` ? html`
@ -148,6 +151,7 @@ export class HuiEntityHeadingBadge
.hass=${this.hass} .hass=${this.hass}
.stateObj=${stateObj} .stateObj=${stateObj}
.content=${config.state_content} .content=${config.state_content}
.name=${config.name}
></state-display> ></state-display>
` `
: nothing} : nothing}

View File

@ -16,6 +16,7 @@ export interface ErrorBadgeConfig extends LovelaceHeadingBadgeConfig {
export interface EntityHeadingBadgeConfig extends LovelaceHeadingBadgeConfig { export interface EntityHeadingBadgeConfig extends LovelaceHeadingBadgeConfig {
type?: "entity"; type?: "entity";
entity: string; entity: string;
name?: string;
state_content?: string | string[]; state_content?: string | string[];
icon?: string; icon?: string;
show_state?: boolean; show_state?: boolean;

View File

@ -6026,6 +6026,8 @@
"entity_config": { "entity_config": {
"color": "[%key:ui::panel::lovelace::editor::card::tile::color%]", "color": "[%key:ui::panel::lovelace::editor::card::tile::color%]",
"color_helper": "[%key:ui::panel::lovelace::editor::card::tile::color_helper%]", "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": "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.", "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", "appearance": "Appearance",