Compare commits

...
Author SHA1 Message Date
WendelinandClaude Opus 5.5 386e7c2ca7 Show the startup toast once translations have loaded
The toast no longer needs English fallbacks for its texts and labels.
It passes translation keys, so the notification manager localizes it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 13:21:48 +01:00
WendelinandClaude Opus 5.5 896523a1e7 Show the startup toast through the notification manager
The "Home Assistant is starting" toast was its own element outside the
notification manager, so a modal dialog made its buttons inert and the
fix from #56063 did not apply to it. It now goes through showToast().

Toasts can now show a supporting text line, and toast actions can be
icon buttons that leave the toast open. The startup toast uses both to
keep its look and its info button.

The startup details are only offered to admins, on the starting toast
and on the completion toast.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 13:14:35 +01:00
6 changed files with 157 additions and 207 deletions

No files matched your search

-117
View File
@@ -1,117 +0,0 @@
import { mdiClose, mdiInformationOutline } from "@mdi/js";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { consumeLocalize } from "../common/decorators/consume-context-entry";
import { fireEvent } from "../common/dom/fire_event";
import type { LocalizeFunc } from "../common/translations/localize";
import { showStartupProgressDialog } from "../dialogs/startup-progress/show-dialog-startup-progress";
import "./ha-icon-button";
@customElement("ha-startup-progress")
export class HaStartupProgress extends LitElement {
// The launch screen render swap would remove a dialog opened before it.
@property({ attribute: false }) public detailsAvailable = false;
@state()
@consumeLocalize()
private _localize!: LocalizeFunc;
// Fallbacks cover the first render, before the core translations have loaded.
protected render() {
const localize = this._localize;
return html`
<div class="card">
<div class="text" role="status">
<span class="title">
${
localize("ui.startup_progress.starting") ||
"Home Assistant is starting"
}
</span>
<span class="secondary">
${
localize("ui.startup_progress.starting_secondary") ||
"Some features may not be available yet"
}
</span>
</div>
${
this.detailsAvailable
? html`<ha-icon-button
.label=${
localize("ui.startup_progress.details") || "Startup details"
}
.path=${mdiInformationOutline}
@click=${this._showDetails}
></ha-icon-button>`
: nothing
}
<ha-icon-button
.label=${localize("ui.notification_toast.dismiss") || "Dismiss"}
.path=${mdiClose}
@click=${this._dismiss}
></ha-icon-button>
</div>
`;
}
private _showDetails() {
showStartupProgressDialog(this);
}
private _dismiss() {
fireEvent(this, "startup-progress-dismissed");
}
static styles = css`
:host {
position: fixed;
inset-inline-start: 50%;
inset-block-end: calc(
var(--safe-area-inset-bottom, 0px) + var(--ha-space-4)
);
transform: translateX(calc(-50% * var(--scale-direction, 1)));
/* Above the launch screen, which can still be fading out. */
z-index: 101;
width: min(420px, calc(100vw - var(--ha-space-8)));
}
.card {
display: flex;
align-items: center;
gap: var(--ha-space-2);
padding: var(--ha-space-3) var(--ha-space-2) var(--ha-space-3)
var(--ha-space-4);
color: var(--ha-color-on-neutral-loud);
background-color: var(--ha-color-neutral-10);
border-radius: var(--ha-border-radius-sm);
box-shadow: var(--wa-shadow-l);
}
.text {
display: flex;
flex-direction: column;
flex: 1;
min-width: 0;
}
.title {
font-weight: var(--ha-font-weight-medium);
}
.secondary {
/* The card is dark in both themes, so the themed quiet color lacks contrast. */
color: var(--ha-color-neutral-70);
font-size: var(--ha-font-size-s);
}
ha-icon-button {
--mdc-icon-button-size: 36px;
color: var(--ha-color-on-neutral-loud);
}
`;
}
declare global {
interface HTMLElementTagNameMap {
"ha-startup-progress": HaStartupProgress;
}
interface HASSDomEvents {
"startup-progress-dismissed": undefined;
}
}
+39 -4
View File
@@ -1,4 +1,4 @@
import { css, html, LitElement } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { classMap } from "lit/directives/class-map";
import {
customElement,
@@ -24,6 +24,8 @@ export interface ToastClosedEventDetail {
export class HaToast extends LitElement {
@property({ attribute: "label-text" }) public labelText = "";
@property({ attribute: "supporting-text" }) public supportingText?: string;
@property({ attribute: "announce-text" }) public announceText?: string;
@property({ type: Number, attribute: "timeout-ms" }) public timeoutMs = 4000;
@@ -234,7 +236,22 @@ export class HaToast extends LitElement {
popoverSupported && !this.stacked ? "manual" : undefined
)}
>
<span class="message">${this.labelText}</span>
<div class="text">
<span
class=${classMap({
message: true,
"has-supporting-text": !!this.supportingText,
})}
>${this.labelText}</span
>
${
this.supportingText
? html`<span class="supporting-text"
>${this.supportingText}</span
>`
: nothing
}
</div>
<div class=${classMap({ actions: true, "has-action": hasAction })}>
<slot name="action"></slot>
<slot name="dismiss"></slot>
@@ -246,7 +263,10 @@ export class HaToast extends LitElement {
aria-live=${this._active ? "polite" : "off"}
aria-atomic="true"
>
${this.announceText ?? this.labelText}
${
this.announceText ??
[this.labelText, this.supportingText].filter(Boolean).join(" ")
}
</span>
`;
}
@@ -306,11 +326,22 @@ export class HaToast extends LitElement {
display: none;
}
.message {
.text {
display: flex;
flex-direction: column;
flex: 1;
min-width: 0;
}
.supporting-text {
color: var(--ha-color-neutral-70);
font-size: var(--ha-font-size-s);
}
.message.has-supporting-text {
font-weight: var(--ha-font-weight-medium);
}
.assistive-message {
position: absolute;
width: 1px;
@@ -330,6 +361,10 @@ export class HaToast extends LitElement {
color: var(--ha-color-on-neutral-loud);
}
::slotted(ha-icon-button) {
margin-inline: calc(var(--ha-space-1) * -1);
}
.actions:not(.has-action) {
display: none;
}
+55 -46
View File
@@ -24,15 +24,16 @@ import "../components/ha-toast";
import type { ToastClosedEventDetail } from "../components/ha-toast";
import type { HomeAssistant } from "../types";
export type ToastText =
| string
| { translationKey: LocalizeKeys; args?: Record<string, string | number> };
export interface ShowToastParams {
// Unique ID for updating or closing a specific toast without flickering.
id?: string;
message:
| string
| { translationKey: LocalizeKeys; args?: Record<string, string | number> };
announceMessage?:
| string
| { translationKey: LocalizeKeys; args?: Record<string, string | number> };
message: ToastText;
supportingText?: ToastText;
announceMessage?: ToastText;
action?: ToastActionParams;
secondaryAction?: ToastActionParams;
dismiss?: () => void;
@@ -44,9 +45,9 @@ export interface ShowToastParams {
export interface ToastActionParams {
action: () => void;
primary?: boolean;
text:
| string
| { translationKey: LocalizeKeys; args?: Record<string, string | number> };
icon?: string;
keepOpen?: boolean;
text: ToastText;
}
interface Notification {
@@ -181,24 +182,9 @@ class NotificationManager extends LitElement {
({ key, parameters }) => html`
<ha-toast
data-notification-key=${key}
.labelText=${
typeof parameters.message !== "string"
? this.hass.localize(
parameters.message.translationKey,
parameters.message.args
)
: parameters.message
}
.announceText=${
parameters.announceMessage
? typeof parameters.announceMessage !== "string"
? this.hass.localize(
parameters.announceMessage.translationKey,
parameters.announceMessage.args
)
: parameters.announceMessage
: undefined
}
.labelText=${this._localizeText(parameters.message)}
.supportingText=${this._localizeText(parameters.supportingText)}
.announceText=${this._localizeText(parameters.announceMessage)}
.timeoutMs=${parameters.duration!}
.stacked=${true}
@toast-closed=${this._toastClosed}
@@ -233,37 +219,61 @@ class NotificationManager extends LitElement {
if (!action) {
return nothing;
}
const onClick = secondary
? this._secondaryButtonClicked
: this._buttonClicked;
if (action.icon) {
return html`
<ha-icon-button
data-notification-key=${key}
.label=${this._localizeText(action.text)}
.path=${action.icon}
slot="action"
@click=${onClick}
></ha-icon-button>
`;
}
return html`
<ha-button
data-notification-key=${key}
appearance=${action.primary ? "filled" : "plain"}
size="s"
slot="action"
@click=${secondary ? this._secondaryButtonClicked : this._buttonClicked}
@click=${onClick}
>
${
typeof action.text !== "string"
? this.hass.localize(action.text.translationKey, action.text.args)
: action.text
}
${this._localizeText(action.text)}
</ha-button>
`;
}
private _buttonClicked(
ev: HASSDomCurrentTargetEvent<HTMLElementTagNameMap["ha-button"]>
) {
const key = ev.currentTarget.dataset.notificationKey!;
this._getToast(key)?.hide("action");
this._getNotification(key)?.parameters.action?.action();
private _localizeText(text: ToastText): string;
private _localizeText(text: ToastText | undefined): string | undefined;
private _localizeText(text: ToastText | undefined) {
return typeof text === "object"
? this.hass.localize(text.translationKey, text.args)
: text;
}
private _secondaryButtonClicked(
ev: HASSDomCurrentTargetEvent<HTMLElementTagNameMap["ha-button"]>
) {
private _buttonClicked(ev: HASSDomCurrentTargetEvent<HTMLElement>) {
const key = ev.currentTarget.dataset.notificationKey!;
this._getToast(key)?.hide("action");
this._getNotification(key)?.parameters.secondaryAction?.action();
this._runAction(key, this._getNotification(key)?.parameters.action);
}
private _secondaryButtonClicked(ev: HASSDomCurrentTargetEvent<HTMLElement>) {
const key = ev.currentTarget.dataset.notificationKey!;
this._runAction(
key,
this._getNotification(key)?.parameters.secondaryAction
);
}
private _runAction(key: string, action: ToastActionParams | undefined) {
if (!action?.keepOpen) {
this._getToast(key)?.hide("action");
}
action?.action();
}
private _dismissClicked(
@@ -332,8 +342,7 @@ class NotificationManager extends LitElement {
inset-inline-end: auto;
inset-block-end: calc(
var(--safe-area-inset-bottom, 0px) + var(--ha-space-4) +
var(--notification-stack-bottom-offset, 0px) +
var(--ha-startup-progress-offset, 0px)
var(--notification-stack-bottom-offset, 0px)
);
inset-inline-start: 50%;
margin: 0;
+43 -39
View File
@@ -1,3 +1,4 @@
import { mdiInformationOutline } from "@mdi/js";
import type { PropertyValues } from "lit";
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import type { BootstrapProgress } from "../data/bootstrap_integrations";
@@ -25,9 +26,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
private _startupFinishPending = false;
private _startupProgressEl?: HTMLElementTagNameMap["ha-startup-progress"];
private _startupProgressResize?: ResizeObserver;
private _startupToastKey?: string;
private _disconnectedTimeout?: number;
@@ -35,7 +34,6 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
super.firstUpdated(changedProps);
// Need to load in advance because when disconnected, can't dynamically load code.
setTimeout(() => import("../managers/notification-manager"), 5000);
setTimeout(() => import("../components/ha-startup-progress"), 5000);
}
updated(changedProperties: PropertyValues<this>) {
@@ -120,6 +118,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
this._startupProgress = undefined;
this._startupFinishPending = false;
this._startupProgressVisible = true;
this._startupToastKey = undefined;
this._subscribedBootstrapProgress = subscribeBootstrapProgress(
this.hass!.connection,
(message) => {
@@ -132,46 +131,49 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
this._updateStartupProgress();
}
private async _updateStartupProgress() {
if (!this._startupProgressVisible) {
private _updateStartupProgress() {
// Wait until the translations are available.
if (
!this._startupProgressVisible ||
!this.hass!.localize("ui.startup_progress.starting")
) {
return;
}
await import("../components/ha-startup-progress");
// Hidden or finished while the component was loading.
if (!this._startupProgressVisible) {
// The launch screen render swap clears the root, which detaches the
// notification manager and would remove a dialog opened before it.
const mainRendered = !!this.renderRoot.querySelector(
"home-assistant-main"
);
const detailsAvailable = mainRendered && !!this.hass!.user?.is_admin;
const key = `${mainRendered}|${detailsAvailable}`;
if (key === this._startupToastKey) {
return;
}
if (!this._startupProgressEl) {
this._startupProgressEl = document.createElement("ha-startup-progress");
this._startupProgressEl.addEventListener(
"startup-progress-dismissed",
() => this._hideStartupProgress()
);
// Lifts the toast stack above the card so neither covers the other.
this._startupProgressResize = new ResizeObserver(() =>
this.style.setProperty(
"--ha-startup-progress-offset",
`calc(${this._startupProgressEl?.offsetHeight ?? 0}px + var(--ha-space-2))`
)
);
this._startupProgressResize.observe(this._startupProgressEl);
}
// The launch screen render swap clears the root, detaching the card.
if (!this._startupProgressEl.isConnected) {
this.renderRoot.appendChild(this._startupProgressEl);
}
this._startupProgressEl.detailsAvailable =
!!this.renderRoot.querySelector("home-assistant-main");
this._startupToastKey = key;
showToast(this, {
id: SERVER_STARTUP_TOAST_ID,
message: { translationKey: "ui.startup_progress.starting" },
supportingText: {
translationKey: "ui.startup_progress.starting_secondary",
},
duration: -1,
dismissable: true,
dismiss: () => this._hideStartupProgress(),
action: detailsAvailable
? {
text: { translationKey: "ui.startup_progress.details" },
icon: mdiInformationOutline,
keepOpen: true,
action: () => showStartupProgressDialog(this),
}
: undefined,
});
}
// Keeps the subscription, so the completion toast still reflects late failures.
private _hideStartupProgress() {
this._startupProgressVisible = false;
this._startupProgressResize?.disconnect();
this._startupProgressResize = undefined;
this.style.removeProperty("--ha-startup-progress-offset");
this._startupProgressEl?.remove();
this._startupProgressEl = undefined;
this._startupToastKey = undefined;
}
// Core can reach RUNNING before its final snapshot with the failures arrives.
@@ -200,10 +202,12 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
})
: this.hass!.localize("ui.notification_toast.started"),
duration: issues ? 10000 : 5000,
action: {
text: this.hass!.localize("ui.notification_toast.details"),
action: () => showStartupProgressDialog(this),
},
action: this.hass!.user?.is_admin
? {
text: this.hass!.localize("ui.notification_toast.details"),
action: () => showStartupProgressDialog(this),
}
: undefined,
});
}
-1
View File
@@ -2972,7 +2972,6 @@
"started_with_issues": "Home Assistant has started. {count, plural,\n one {# integration needs}\n other {# integrations need}\n} attention.",
"details": "Details",
"triggered": "Triggered {name}",
"dismiss": "Dismiss",
"no_matching_link_found": "No matching My link found for {path}",
"new_version_available": "A new version of the frontend is available. This page will update in {seconds, plural, one {# second} other {# seconds}}.",
"new_version_available_reload": "A new version of the frontend is available. It will be applied once you have finished what you are working on.",
@@ -144,6 +144,26 @@ describe("notification-manager", () => {
expect(primary).toHaveBeenCalledOnce();
});
it("keeps the toast open after a keepOpen icon action", async () => {
const manager = await mountManager();
const action = vi.fn();
await manager.showDialog({
message: "Starting",
action: { action, icon: "M0 0", keepOpen: true, text: "Details" },
duration: -1,
});
const toast = manager.shadowRoot!.querySelector("ha-toast")!;
const button = manager.shadowRoot!.querySelector(
"ha-icon-button[slot='action']"
) as HTMLElement;
button.click();
expect(action).toHaveBeenCalledOnce();
expect(toast.hide).not.toHaveBeenCalled();
});
it("invokes the action belonging to the selected stacked toast", async () => {
const manager = await mountManager();
const firstAction = vi.fn();