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
30 changes: 24 additions & 6 deletions src/data/system_log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,27 @@ export interface LoggedError {
export const fetchSystemLog = (hass: HomeAssistant) =>
hass.callApi<LoggedError[]>("GET", "error/all");

export const getLoggedErrorIntegration = (item: LoggedError) =>
item.name.startsWith("homeassistant.components.")
? item.name.split(".")[2]
: item.name.startsWith("custom_components.")
? item.name.split(".")[1]
: undefined;
export const getLoggedErrorIntegration = (item: LoggedError) => {
// Try to derive from logger name
if (item.name.startsWith("homeassistant.components.")) {
return item.name.split(".")[2];
}
if (item.name.startsWith("custom_components.")) {
return item.name.split(".")[1];
}

// Try to derive from logged location
if (item.source[0].startsWith("custom_components/")) {
return item.source[0].split("/")[1];
}

if (item.source[0].startsWith("homeassistant/components/")) {
return item.source[0].split("/")[2];
}

return undefined;
};

export const isCustomIntegrationError = (item: LoggedError) =>
item.name.startsWith("custom_components.") ||
item.source[0].startsWith("custom_components/");
53 changes: 49 additions & 4 deletions src/panels/config/logs/dialog-system-log-detail.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "@material/mwc-icon-button/mwc-icon-button";
import { mdiClose, mdiContentCopy } from "@mdi/js";
import { mdiClose, mdiContentCopy, mdiPackageVariant } from "@mdi/js";
import "@polymer/paper-tooltip/paper-tooltip";
import {
css,
Expand All @@ -21,7 +21,10 @@ import {
integrationIssuesUrl,
IntegrationManifest,
} from "../../../data/integration";
import { getLoggedErrorIntegration } from "../../../data/system_log";
import {
getLoggedErrorIntegration,
isCustomIntegrationError,
} from "../../../data/system_log";
import { haStyleDialog } from "../../../resources/styles";
import type { HomeAssistant } from "../../../types";
import { showToast } from "../../../util/toast";
Expand Down Expand Up @@ -65,6 +68,12 @@ class DialogSystemLogDetail extends LitElement {

const integration = getLoggedErrorIntegration(item);

const showDocumentation =
this._manifest &&
(this._manifest.is_built_in ||
// Custom components with our offical docs should not link to our docs
!this._manifest.documentation.includes("www.home-assistant.io"));

return html`
<ha-dialog open @closed=${this.closeDialog} hideActions heading=${true}>
<ha-header-bar slot="heading">
Expand All @@ -86,6 +95,14 @@ class DialogSystemLogDetail extends LitElement {
<ha-svg-icon .path=${mdiContentCopy}></ha-svg-icon>
</mwc-icon-button>
</ha-header-bar>
${this.isCustomIntegration
? html`<div class="custom">
<ha-svg-icon .path=${mdiPackageVariant}></ha-svg-icon>
${this.hass.localize(
"ui.panel.config.logs.error_from_custom_integration"
)}
</div>`
: ""}
<div class="contents">
<p>
Logger: ${item.name}<br />
Expand All @@ -96,7 +113,7 @@ class DialogSystemLogDetail extends LitElement {
Integration: ${domainToName(this.hass.localize, integration)}
${!this._manifest ||
// Can happen with custom integrations
!this._manifest.documentation
!showDocumentation
? ""
: html`
(<a
Expand Down Expand Up @@ -144,6 +161,12 @@ class DialogSystemLogDetail extends LitElement {
`;
}

private get isCustomIntegration(): boolean {
return this._manifest
? !this._manifest.is_built_in
: isCustomIntegrationError(this._params!.item);
}

private async _fetchManifest(integration: string) {
try {
this._manifest = await fetchIntegrationManifest(this.hass, integration);
Expand All @@ -157,7 +180,18 @@ class DialogSystemLogDetail extends LitElement {
".contents"
) as HTMLElement;

await copyToClipboard(copyElement.innerText);
let text = copyElement.innerText;

if (this.isCustomIntegration) {
text =
this.hass.localize(
"ui.panel.config.logs.error_from_custom_integration"
) +
"\n\n" +
text;
}

await copyToClipboard(text);
showToast(this, {
message: this.hass.localize("ui.common.copied_clipboard"),
});
Expand All @@ -167,6 +201,10 @@ class DialogSystemLogDetail extends LitElement {
return [
haStyleDialog,
css`
ha-dialog {
--dialog-content-padding: 0px;
}

a {
color: var(--primary-color);
}
Expand All @@ -177,6 +215,13 @@ class DialogSystemLogDetail extends LitElement {
margin-bottom: 0;
font-family: var(--code-font-family, monospace);
}
.custom {
padding: 8px 16px;
background-color: var(--warning-color);
}
.contents {
padding: 16px;
}
.error {
color: var(--error-color);
}
Expand Down
11 changes: 9 additions & 2 deletions src/panels/config/logs/system-log-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { domainToName } from "../../../data/integration";
import {
fetchSystemLog,
getLoggedErrorIntegration,
isCustomIntegrationError,
LoggedError,
} from "../../../data/system_log";
import { HomeAssistant } from "../../../types";
Expand Down Expand Up @@ -78,10 +79,16 @@ export class SystemLogCard extends LitElement {
)}</span
>) `}
${integrations[idx]
? domainToName(
? `${domainToName(
this.hass!.localize,
integrations[idx]!
)
)}${
isCustomIntegrationError(item)
? ` (${this.hass.localize(
"ui.panel.config.logs.custom_integration"
)})`
: ""
}`
: item.source[0]}
${item.count > 1
? html`
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,9 @@
"warning": "WARNING",
"info": "INFO",
"debug": "DEBUG"
}
},
"custom_integration": "custom integration",
"error_from_custom_integration": "This error originated from a custom integration."
},
"lovelace": {
"caption": "Lovelace Dashboards",
Expand Down