mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-08 02:19:43 +00:00
* Use literal type for system log level * Fix typo in URL error title key * Remove localize key exceptions
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { HomeAssistant, TranslationDict } from "../types";
|
|
|
|
export interface LoggedError {
|
|
name: string;
|
|
message: [string];
|
|
level: keyof TranslationDict["ui"]["panel"]["config"]["logs"]["level"];
|
|
source: [string, number];
|
|
// unix timestamp in seconds
|
|
timestamp: number;
|
|
exception: string;
|
|
count: number;
|
|
// unix timestamp in seconds
|
|
first_occurred: number;
|
|
}
|
|
|
|
export const fetchSystemLog = async (hass: HomeAssistant) => {
|
|
const log = await hass.callWS<LoggedError[]>({ type: "system_log/list" });
|
|
for (const error of log) {
|
|
error.level = error.level.toLowerCase() as LoggedError["level"];
|
|
}
|
|
return log;
|
|
};
|
|
|
|
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/");
|