Skip to content

Commit

Permalink
Add fallback for missing logs boot result.
Browse files Browse the repository at this point in the history
  • Loading branch information
wendevlin committed Oct 30, 2024
1 parent eb8d233 commit cc633dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/data/hassio/supervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ export const fetchHassioLogs = async (
);

export const fetchHassioLogsFollow = async (
hass: HomeAssistant,
provider: string,
signal: AbortSignal,
lines = 100
) =>
hass.callApiRaw(
"GET",
`hassio/${provider.includes("_") ? `addons/${provider}` : provider}/logs/follow?lines=${lines}`,
undefined,
undefined,
signal
);

export const fetchHassioLogsBootFollow = async (
hass: HomeAssistant,
provider: string,
signal: AbortSignal,
Expand Down
16 changes: 14 additions & 2 deletions src/panels/config/logs/error-log-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { extractApiErrorMessage } from "../../../data/hassio/common";
import {
fetchHassioBoots,
fetchHassioLogs,
fetchHassioLogsBootFollow,
fetchHassioLogsFollow,
getHassioLogDownloadUrl,
} from "../../../data/hassio/supervisor";
Expand Down Expand Up @@ -378,7 +379,7 @@ class ErrorLogCard extends LitElement {
isComponentLoaded(this.hass, "hassio") &&
this.provider
) {
const response = await fetchHassioLogsFollow(
const response = await this._fetchLogs()(
this.hass,
this.provider,
this._logStreamAborter.signal,
Expand Down Expand Up @@ -468,6 +469,13 @@ class ErrorLogCard extends LitElement {
}
}

private _fetchLogs = () => {
if (this._boot === 0) {
return fetchHassioLogsFollow;
}
return fetchHassioLogsBootFollow;
};

private _debounceSearch = debounce(() => {
this._noSearchResults = !this._ansiToHtmlElement?.filterLines(this.filter);

Expand Down Expand Up @@ -570,9 +578,13 @@ class ErrorLogCard extends LitElement {
if (this._streamSupported && isComponentLoaded(this.hass, "hassio")) {
try {
const { data } = await fetchHassioBoots(this.hass);
this._boots = Object.keys(data.boots)
const boots = Object.keys(data.boots)
.map(Number)
.sort((a, b) => b - a);

if (boots.length) {
this._boots = boots;
}
} catch (err: any) {
// eslint-disable-next-line no-console
console.error(err);
Expand Down

0 comments on commit cc633dc

Please sign in to comment.