Show the integration brand icon when there is no entity in logbook (#12713)

This commit is contained in:
J. Nick Koston 2022-05-18 14:01:09 -05:00 committed by GitHub
parent af6b0d3266
commit f4f51e1de5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 12 deletions

View File

@ -46,6 +46,20 @@ export const domainIcon = (
stateObj?: HassEntity, stateObj?: HassEntity,
state?: string state?: string
): 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; const compareState = state !== undefined ? state : stateObj?.state;
switch (domain) { switch (domain) {
@ -150,7 +164,5 @@ export const domainIcon = (
return FIXED_DOMAIN_ICONS[domain]; return FIXED_DOMAIN_ICONS[domain];
} }
// eslint-disable-next-line return undefined;
console.warn(`Unable to find icon for domain ${domain}`);
return DEFAULT_DOMAIN_ICON;
}; };

View File

@ -15,7 +15,8 @@ import { formatTimeWithSeconds } from "../../common/datetime/format_time";
import { restoreScroll } from "../../common/decorators/restore-scroll"; import { restoreScroll } from "../../common/decorators/restore-scroll";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import { computeDomain } from "../../common/entity/compute_domain"; 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 { computeRTL, emitRTLDirection } from "../../common/util/compute_rtl";
import "../../components/entity/state-badge"; import "../../components/entity/state-badge";
import "../../components/ha-circular-progress"; import "../../components/ha-circular-progress";
@ -28,6 +29,7 @@ import {
buttonLinkStyle, buttonLinkStyle,
} from "../../resources/styles"; } from "../../resources/styles";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
import { brandsUrl } from "../../util/brands-url";
const EVENT_LOCALIZE_MAP = { const EVENT_LOCALIZE_MAP = {
script_started: "from_script", script_started: "from_script",
@ -138,6 +140,26 @@ class HaLogbookRenderer extends LitElement {
? computeDomain(item.entity_id) ? computeDomain(item.entity_id)
: // Domain is there if there is no entity ID. : // Domain is there if there is no entity ID.
item.domain!; 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)
? brandsUrl({
domain: item.domain!,
type: "icon",
useFallback: true,
darkOptimized: this.hass.themes?.darkMode,
})
: undefined)
: undefined;
return html` return html`
<div class="entry-container"> <div class="entry-container">
@ -161,14 +183,8 @@ class HaLogbookRenderer extends LitElement {
html` html`
<state-badge <state-badge
.hass=${this.hass} .hass=${this.hass}
.overrideIcon=${item.icon || .overrideIcon=${overrideIcon}
(item.domain && !stateObj .overrideImage=${overrideImage}
? domainIcon(item.domain!)
: undefined)}
.overrideImage=${DOMAINS_WITH_DYNAMIC_PICTURE.has(domain)
? ""
: stateObj?.attributes.entity_picture_local ||
stateObj?.attributes.entity_picture}
.stateObj=${stateObj} .stateObj=${stateObj}
.stateColor=${false} .stateColor=${false}
></state-badge> ></state-badge>