Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Landingpage add core checks before show errors #24493

Merged
merged 10 commits into from
Mar 6, 2025
4 changes: 2 additions & 2 deletions landing-page/src/components/landing-page-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { fireEvent } from "../../../src/common/dom/fire_event";
import { fileDownload } from "../../../src/util/file_download";
import { getSupervisorLogs, getSupervisorLogsFollow } from "../data/supervisor";
import { waitForSeconds } from "../../../src/common/util/wait";
import { CORE_CHECK_SECONDS } from "../ha-landing-page";
import { ASSUME_CORE_START_SECONDS } from "../ha-landing-page";

const ERROR_CHECK = /^[\d\s-:]+(ERROR|CRITICAL)(.*)/gm;
declare global {
Expand Down Expand Up @@ -254,7 +254,7 @@ class LandingPageLogs extends LitElement {
this._scheduleObserverLogs();
} catch (err) {
// wait because there is a moment where landingpage is down and core is not up yet
await waitForSeconds(CORE_CHECK_SECONDS);
await waitForSeconds(ASSUME_CORE_START_SECONDS);

// eslint-disable-next-line no-console
console.error(err);
Expand Down
19 changes: 14 additions & 5 deletions landing-page/src/ha-landing-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { extractSearchParam } from "../../src/common/url/search-params";
import { onBoardingStyles } from "../../src/onboarding/styles";
import { makeDialogManager } from "../../src/dialogs/make-dialog-manager";
import { LandingPageBaseElement } from "./landing-page-base-element";
import { waitForSeconds } from "../../src/common/util/wait";
import {
getSupervisorNetworkInfo,
pingSupervisor,
type NetworkInfo,
} from "./data/supervisor";

export const CORE_CHECK_SECONDS = 5;
export const ASSUME_CORE_START_SECONDS = 30;
export const SCHEDULE_CORE_CHECK_SECONDS = 5;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used? We only check core status once now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do check core status on every fail of _fetchSupervisorInfo, I changed it now that when we are in core check mode we run _fetchSupervisorInfo every second.

const SCHEDULE_FETCH_NETWORK_INFO_SECONDS = 5;

@customElement("ha-landing-page")
Expand All @@ -32,6 +32,8 @@ class HaLandingPage extends LandingPageBaseElement {

@state() private _networkInfoError = false;

@state() private _coreCheckActive = false;

private _mobileApp =
extractSearchParam("redirect_uri") === "homeassistant://auth-callback";

Expand Down Expand Up @@ -116,6 +118,12 @@ class HaLandingPage extends LandingPageBaseElement {
);
}

private _turnOfCoreCheck() {
setTimeout(() => {
this._coreCheckActive = false;
}, ASSUME_CORE_START_SECONDS * 1000);
}

private async _fetchSupervisorInfo(schedule = false) {
try {
if (!this._networkInfo) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we only ping once? are we sure that supervisor wont go down after we have a ping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it should not go down till core starts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it goes down when it updates, are we sure it will be done for update before we do the first check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood it like this but I'll recheck

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is updated that we assume a supervisor update when ping doesn't work and don't show errors.

Expand All @@ -130,13 +138,14 @@ class HaLandingPage extends LandingPageBaseElement {
this._coreStatusChecked = false;
} catch (err: any) {
if (!this._coreStatusChecked) {
// wait because there is a moment where landingpage is down and core is not up yet
await waitForSeconds(CORE_CHECK_SECONDS);
// wait before show errors, because we assume that core is starting
this._coreCheckActive = true;
this._turnOfCoreCheck();
}
await this._checkCoreAvailability();

// assume supervisor update if ping fails and network info was never fetched -> don't show an error
if (err.message !== "ping-failed") {
if (!this._coreCheckActive && err.message !== "ping-failed") {
// eslint-disable-next-line no-console
console.error(err);
this._networkInfoError = true;
Expand Down
Loading