Use entity registry icon directly (#19466)

This commit is contained in:
Bram Kragten 2024-01-19 15:42:20 +01:00 committed by GitHub
parent 619675318c
commit 809df848ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 4 deletions

View File

@ -17,10 +17,12 @@ export class HaStateIcon extends LitElement {
@property() public icon?: string;
protected render() {
if (this.icon || this.stateObj?.attributes.icon) {
return html`<ha-icon
.icon=${this.icon || this.stateObj?.attributes.icon}
></ha-icon>`;
const overrideIcon =
this.icon ||
(this.stateObj && this.hass?.entities[this.stateObj.entity_id]?.icon) ||
this.stateObj?.attributes.icon;
if (overrideIcon) {
return html`<ha-icon .icon=${overrideIcon}></ha-icon>`;
}
if (!this.stateObj) {
return nothing;

View File

@ -15,6 +15,7 @@ type entityCategory = "config" | "diagnostic";
export interface EntityRegistryDisplayEntry {
entity_id: string;
name?: string;
icon?: string;
device_id?: string;
area_id?: string;
hidden?: boolean;
@ -31,6 +32,7 @@ export interface EntityRegistryDisplayEntryResponse {
ai?: string;
ec?: number;
en?: string;
ic?: string;
pl?: string;
tk?: string;
hb?: boolean;

View File

@ -75,6 +75,9 @@ export const entityIcon = async (hass: HomeAssistant, state: HassEntity) => {
let icon: string | undefined;
const domain = computeStateDomain(state);
const entity = hass.entities?.[state.entity_id];
if (entity?.icon) {
return entity.icon;
}
if (entity?.translation_key && entity.platform) {
const platformIcons = await getPlatformIcons(hass, entity.platform);
if (platformIcons) {

View File

@ -239,6 +239,7 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
? entityReg.entity_categories[entity.ec]
: undefined,
name: entity.en,
icon: entity.ic,
hidden: entity.hb,
display_precision: entity.dp,
};