1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-17 07:34:21 +01:00
Files
frontend/src/data/system_log.ts
Wendelin 830d8d2410 Add type import check to eslint (#22488)
* Add type import check to eslint

* Add type imports with eslint --fix
2024-10-30 11:12:30 +00:00

54 lines
1.3 KiB
TypeScript

import type { HomeAssistant } from "../types";
export type SystemLogLevel =
| "critical"
| "error"
| "warning"
| "info"
| "debug";
export interface LoggedError {
name: string;
message: [string];
level: SystemLogLevel;
source: [string, number];
exception: string;
count: number;
// unix timestamps in seconds
timestamp: number;
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/");