Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/common/entity/domain_icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ export const domainIcon = (
stateObj?: HassEntity,
state?: string
): string => {
const icon = domainIconWithoutDefault(domain, stateObj, state);
if (icon) {
return icon;
}
// eslint-disable-next-line
console.warn(`Unable to find icon for domain ${domain}`);
return DEFAULT_DOMAIN_ICON;
};

export const domainIconWithoutDefault = (
domain: string,
stateObj?: HassEntity,
state?: string
): string | undefined => {
const compareState = state !== undefined ? state : stateObj?.state;

switch (domain) {
Expand Down Expand Up @@ -150,7 +164,5 @@ export const domainIcon = (
return FIXED_DOMAIN_ICONS[domain];
}

// eslint-disable-next-line
console.warn(`Unable to find icon for domain ${domain}`);
return DEFAULT_DOMAIN_ICON;
return undefined;
};
34 changes: 25 additions & 9 deletions src/panels/logbook/ha-logbook-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { formatTimeWithSeconds } from "../../common/datetime/format_time";
import { restoreScroll } from "../../common/decorators/restore-scroll";
import { fireEvent } from "../../common/dom/fire_event";
import { computeDomain } from "../../common/entity/compute_domain";
import { domainIcon } from "../../common/entity/domain_icon";
import { domainIconWithoutDefault } from "../../common/entity/domain_icon";
import { isComponentLoaded } from "../../common/config/is_component_loaded";
import { computeRTL, emitRTLDirection } from "../../common/util/compute_rtl";
import "../../components/entity/state-badge";
import "../../components/ha-circular-progress";
Expand All @@ -28,6 +29,7 @@ import {
buttonLinkStyle,
} from "../../resources/styles";
import { HomeAssistant } from "../../types";
import { brandsUrl } from "../../util/brands-url";

const EVENT_LOCALIZE_MAP = {
script_started: "from_script",
Expand Down Expand Up @@ -138,6 +140,26 @@ class HaLogbookRenderer extends LitElement {
? computeDomain(item.entity_id)
: // Domain is there if there is no entity ID.
item.domain!;
const overrideIcon =
item.icon ||
(item.domain && !stateObj
? domainIconWithoutDefault(item.domain!)
: undefined);
const overrideImage = !DOMAINS_WITH_DYNAMIC_PICTURE.has(domain)
? stateObj?.attributes.entity_picture_local ||
stateObj?.attributes.entity_picture ||
(!stateObj &&
!overrideIcon &&
item.domain &&
isComponentLoaded(this.hass, item.domain)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why guard if it's loaded?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured we didn't want the overhead of loading an image if it was likely to not exist and they would get 'icon not found' image which didn't look so hot in this context

? brandsUrl({
domain: item.domain!,
type: "icon",
useFallback: true,
darkOptimized: this.hass.themes?.darkMode,
})
: undefined)
: undefined;

return html`
<div class="entry-container">
Expand All @@ -161,14 +183,8 @@ class HaLogbookRenderer extends LitElement {
html`
<state-badge
.hass=${this.hass}
.overrideIcon=${item.icon ||
(item.domain && !stateObj
? domainIcon(item.domain!)
: undefined)}
.overrideImage=${DOMAINS_WITH_DYNAMIC_PICTURE.has(domain)
? ""
: stateObj?.attributes.entity_picture_local ||
stateObj?.attributes.entity_picture}
.overrideIcon=${overrideIcon}
.overrideImage=${overrideImage}
.stateObj=${stateObj}
.stateColor=${false}
></state-badge>
Expand Down