mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Add restart in safe mode in restart dialog (#18375)
This commit is contained in:
parent
c840f1cbb1
commit
8350d71f6e
@ -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";
|
||||
@ -14,8 +20,8 @@ import {
|
||||
ignoreSupervisorError,
|
||||
} from "../../data/hassio/common";
|
||||
import {
|
||||
fetchHassioHostInfo,
|
||||
HassioHostInfo,
|
||||
fetchHassioHostInfo,
|
||||
rebootHost,
|
||||
shutdownHost,
|
||||
} from "../../data/hassio/host";
|
||||
@ -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 {
|
||||
@ -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
|
||||
@ -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>
|
||||
`;
|
||||
@ -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;
|
||||
@ -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);
|
||||
|
@ -1233,6 +1233,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": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user