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

Add restart in safe mode in restart dialog #18375

Merged
merged 3 commits into from
Oct 24, 2023
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
118 changes: 90 additions & 28 deletions src/dialogs/restart/dialog-restart.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import "@material/mwc-list/mwc-list";
import { mdiAutoFix, mdiPower, mdiPowerCycle, mdiRefresh } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import {
mdiAutoFix,
mdiLifebuoy,
mdiPower,
mdiPowerCycle,
mdiRefresh,
} from "@mdi/js";
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { isComponentLoaded } from "../../common/config/is_component_loaded";
import { fireEvent } from "../../common/dom/fire_event";
Expand All @@ -14,8 +20,8 @@ import {
ignoreSupervisorError,
} from "../../data/hassio/common";
import {
fetchHassioHostInfo,
HassioHostInfo,
fetchHassioHostInfo,
rebootHost,
shutdownHost,
} from "../../data/hassio/host";
Expand Down Expand Up @@ -54,18 +60,6 @@ class DialogRestart extends LitElement {
this._loadingHostInfo = false;
}
}

const showReload = this.hass.userData?.showAdvanced;
const showRebootShutdown = !!this._hostInfo;

// Present restart core dialog if no host actions and not advanced mode as it's the only option
if (!showReload && !showRebootShutdown) {
this._open = false;
this._showRestartDialog().then(() => this.closeDialog());
return;
}

await this.updateComplete;
}

public closeDialog(): void {
Expand Down Expand Up @@ -145,15 +139,14 @@ class DialogRestart extends LitElement {
</span>
</ha-list-item>
</mwc-list>

${showRebootShutdown
? html`
<ha-expansion-panel
.header=${this.hass.localize(
"ui.dialogs.restart.advanced_options"
)}
>
<mwc-list>
<ha-expansion-panel
.header=${this.hass.localize(
"ui.dialogs.restart.advanced_options"
)}
>
<mwc-list>
${showRebootShutdown
? html`
<ha-list-item
graphic="avatar"
twoline
Expand Down Expand Up @@ -196,10 +189,34 @@ class DialogRestart extends LitElement {
)}
</span>
</ha-list-item>
</mwc-list>
</ha-expansion-panel>
`
: nothing}
`
: nothing}
<ha-list-item
graphic="avatar"
twoline
multiline-secondary
hasMeta
@request-selected=${this._restartSafeMode}
>
<div
slot="graphic"
class="icon-background restart-safe-mode"
>
<ha-svg-icon .path=${mdiLifebuoy}></ha-svg-icon>
</div>
<span>
${this.hass.localize(
"ui.dialogs.restart.restart-safe-mode.title"
)}
</span>
<span slot="secondary">
${this.hass.localize(
"ui.dialogs.restart.restart-safe-mode.description"
)}
</span>
</ha-list-item>
</mwc-list>
</ha-expansion-panel>
`}
</ha-dialog>
`;
Expand Down Expand Up @@ -262,6 +279,47 @@ class DialogRestart extends LitElement {
}
}

private async _restartSafeMode(ev) {
if (!shouldHandleRequestSelectedEvent(ev)) {
return;
}
this._showRestartSafeModeDialog();
}

private async _showRestartSafeModeDialog() {
const confirmed = await showConfirmationDialog(this, {
title: this.hass.localize(
"ui.dialogs.restart.restart-safe-mode.confirm_title"
),
text: this.hass.localize(
"ui.dialogs.restart.restart-safe-mode.confirm_description"
),
confirmText: this.hass.localize(
"ui.dialogs.restart.restart-safe-mode.confirm_action"
),
destructive: true,
});

if (!confirmed) {
return;
}

this.closeDialog();

try {
await this.hass.callService("homeassistant", "restart", {
safe_mode: true,
});
} catch (err: any) {
showAlertDialog(this, {
title: this.hass.localize(
"ui.dialogs.restart.restart-safe-mode.failed"
),
text: err.message,
});
}
}

private async _hostReboot(ev): Promise<void> {
if (!shouldHandleRequestSelectedEvent(ev)) {
return;
Expand Down Expand Up @@ -382,6 +440,10 @@ class DialogRestart extends LitElement {
background-color: #0b1d29;
color: #fff;
}
.restart-safe-mode {
background-color: #e48629;
color: #fff;
}
.divider {
height: 1px;
background-color: var(--divider-color);
Expand Down
8 changes: 8 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,14 @@
"confirm_action": "Shut down",
"shutting_down": "Shutting down system",
"failed": "Failed to shut down system"
},
"restart-safe-mode": {
"title": "Restart Home Assistant in safe mode",
"description": "Restart Home Assistant without loading any custom integrations and modules.",
"confirm_title": "Restart Home Assistant in safe mode?",
"confirm_description": "This will restart Home Assistant without loading any custom integrations and modules.",
"confirm_action": "Restart",
"failed": "Failed to restart Home Assistant"
}
},
"aliases": {
Expand Down
Loading