Compare commits

..
Author SHA1 Message Date
Maarten Lakerveld ff773e3045 Put the mobile tab bar after the page content in focus order
On narrow screens the subpage tabs sit at the bottom of the screen but
came before the content in the DOM, so keyboard and screen reader focus
jumped from the header to the bottom bar and back up. Render the bottom
bar after the content and FAB so focus follows the visual order.

Both tab bars are now a labelled nav landmark, so screen reader users
can still jump straight to the tabs without going through long lists.

fixes #14117
2026-11-19 11:40:05 +01:00
15 changed files with 184 additions and 335 deletions

No files matched your search

+2 -11
View File
@@ -250,16 +250,7 @@ class DemoMoreInfoUpdate extends LitElement {
"update/release_notes",
(msg: { type: string; entity_id: string }) => {
if (msg.entity_id === "update.update16") {
return {
release_notes: LONG_TEXT,
messages: [
{
severity: "warning",
message:
"Do not restart, remove power from, or otherwise interrupt the device while the update is in progress.",
},
],
};
return LONG_TEXT;
}
if (msg.entity_id === "update.update17") {
return Promise.reject({
@@ -270,7 +261,7 @@ class DemoMoreInfoUpdate extends LitElement {
if (msg.entity_id === "update.update18") {
return undefined;
}
return { release_notes: null, messages: [] };
return null;
}
);
}
+2 -2
View File
@@ -83,7 +83,7 @@
"@vibrant/color": "4.0.4",
"@vvo/tzdb": "6.204.0",
"@webcomponents/scoped-custom-element-registry": "0.0.10",
"barcode-detector": "3.2.4",
"barcode-detector": "3.2.3",
"cally": "0.9.2",
"color-name": "2.1.1",
"comlink": "4.4.2",
@@ -199,7 +199,7 @@
"jszip": "3.10.2",
"license-checker-rseidelsohn": "5.0.1",
"lightningcss": "1.33.0",
"lint-staged": "17.6.1",
"lint-staged": "17.6.0",
"lit-analyzer": "2.0.3",
"lodash.merge": "4.6.2",
"lodash.template": "4.18.1",
+19 -19
View File
@@ -318,8 +318,8 @@ importers:
specifier: 0.0.10
version: 0.0.10
barcode-detector:
specifier: 3.2.4
version: 3.2.4
specifier: 3.2.3
version: 3.2.3
cally:
specifier: 0.9.2
version: 0.9.2
@@ -661,8 +661,8 @@ importers:
specifier: 1.33.0
version: 1.33.0
lint-staged:
specifier: 17.6.1
version: 17.6.1
specifier: 17.6.0
version: 17.6.0
lit-analyzer:
specifier: 2.0.3
version: 2.0.3
@@ -4245,8 +4245,8 @@ packages:
resolution: {integrity: sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==}
engines: {node: 18 || 20 || >=22}
[email protected].4:
resolution: {integrity: sha512-4tjallFXSratRbkzyccnfgL8w/3FtTexjWpQoPes3niFQ2DybGeaktH8w5ukc6wVUrOL7yNsoUUqmaRVn1YtJg==}
[email protected].3:
resolution: {integrity: sha512-PLinpWGiOQoQH4X+YObWZ6iXeffXKDM3d4vnOD86481SvukIfvkf7jEE/tud9oI4HTDxtDdlHaFilA5Kn7Xa7A==}
[email protected]:
resolution: {integrity: sha512-Z0oHEHAFDZkffN8Qc39zNZjQlMDkPJRyyyZieU1VH7u8c5S+qHZ2S8ixdKIAxEjfHO7FJxXmJWgteOghVanIsg==}
@@ -6064,8 +6064,8 @@ packages:
resolution: {integrity: sha512-wM1+Z03eypVAVUCE7QdSqpVIvelbOakn1M0bPDoA4SGWPx3sNDVUiMo3L6To6WWGClB7VyXnhQ4Sn7gxiJbE6A==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
[email protected].1:
resolution: {integrity: sha512-3MXgVN7BERDR/6CXZs2fDHGc+r0+hlvGAa9wqMlVbIS6RVRuaPOnb5SnN6wMXulwfEy9DXVkMVUN/8cUlpPDnw==}
[email protected].0:
resolution: {integrity: sha512-nOhBfYkZEwkFtNzD5pK9s9LkcWoxJ+whLzEnhqi9nl7zTB5n7tg8+9iYgMGx2Wm3VlLu8cbNj0RACzY+nWi5iQ==}
engines: {node: '>=22.22.1'}
hasBin: true
@@ -7259,9 +7259,9 @@ packages:
[email protected]:
resolution: {integrity: sha512-1Yowhzjf0ivGMrTIkY9hav5TxobO9qIVqUE41fiCGMGgc3CLlf4MY+9AHmZqBWgDTue0fY9zWjYFVyf6Diuobw==}
string-argv@0.4.0:
resolution: {integrity: sha512-UOtaksJ3SK3KLHba2i9I27fvuZNfBlImDP5wKsCOxCDMRDNxlipCe8rmnUAaDpqlQ93upnA0SzF2pjWhttozSA==}
engines: {node: '>=16.20.0'}
string-argv@0.3.2:
resolution: {integrity: sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==}
engines: {node: '>=0.6.19'}
[email protected]:
resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==}
@@ -8143,8 +8143,8 @@ packages:
[email protected]:
resolution: {integrity: sha512-oEGMDB6pOP2S6OwRR4PdVv610zrjnA3Bh+JnSG12fYJlBKjtNAoEb5fSUoCOOINlH96I2fU38/A2UpRKs67xYQ==}
[email protected].7:
resolution: {integrity: sha512-LI94ndlOY+xoqlkNcc0EwByrMpUXKrCX171EQ38kGWqpiRq/gcnC+ZrbRipvxI3uV4LaDtNlKo1p9Uayg1sesQ==}
[email protected].6:
resolution: {integrity: sha512-mU7UNuvl+hOT+nlSOQTMHZ2tM8lRMsbjDIp5IO/+HmBl/FOq77q0OSZPJ3cm42A9c1MKU6Uve67FiGdkhsrT9g==}
peerDependencies:
'@types/emscripten': '>=1.39.6'
@@ -11992,9 +11992,9 @@ snapshots:
[email protected]: {}
[email protected].4:
[email protected].3:
dependencies:
zxing-wasm: 3.1.7
zxing-wasm: 3.1.6
[email protected]: {}
@@ -13964,10 +13964,10 @@ snapshots:
[email protected]: {}
[email protected].1:
[email protected].0:
dependencies:
picomatch: 4.0.7
string-argv: 0.4.0
string-argv: 0.3.2
tinyexec: 1.3.1
optionalDependencies:
yaml: 2.9.1
@@ -15370,7 +15370,7 @@ snapshots:
- bare-abort-controller
- react-native-b4a
string-argv@0.4.0: {}
string-argv@0.3.2: {}
[email protected]:
dependencies:
@@ -16333,7 +16333,7 @@ snapshots:
dependencies:
tslib: 2.9.1
[email protected].7:
[email protected].6:
dependencies:
'@types/emscripten': 1.41.6
type-fest: 5.10.0
-57
View File
@@ -95,10 +95,6 @@ const SELECTED_NODE_FIT_MARGIN = 72;
const FOLLOW_ROAM = "follow-selected-node";
type Displayable = ReturnType<
ReturnType<EChartsType["getZr"]>["storage"]["getDisplayList"]
>[number];
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/consistent-type-imports
let GraphChart: typeof import("echarts/lib/chart/graph/install");
@@ -156,8 +152,6 @@ export class HaNetworkGraph extends LitElement {
private _dragMoved = false;
private _dragTarget?: Displayable;
private _followSelectedNode = false;
private _followedChart?: EChartsType;
@@ -571,7 +565,6 @@ export class HaNetworkGraph extends LitElement {
private _handleChartSetup() {
const chart = this._baseChart?.chart;
chart?.on("mousedown", this._handleNodeMouseDown);
chart?.getZr().on("dragstart", this._handleDragStart);
chart?.getZr().on("drag", this._handleDrag);
chart?.getZr().on("dragend", this._handleDragEnd);
for (const event of LEGEND_SELECT_EVENTS) {
@@ -615,54 +608,6 @@ export class HaNetworkGraph extends LitElement {
this._dragMoved = false;
};
// The dragged element gets the drag before the ECharts handler of its node
private _handleDragStart = (ev: { target?: Displayable }) => {
this._dragTarget?.off("drag", this._handleNodeDrag);
this._dragTarget = ev.target;
this._dragTarget?.on("drag", this._handleNodeDrag);
};
// Without layout animation, the ECharts handler runs the whole force layout
// on every move, which puts the node back before it reads its position. So
// the node moves here, and the other nodes stay where they are.
private _handleNodeDrag = (ev: { cancelBubble?: boolean }) => {
const chart = this._baseChart?.chart;
const series = this._getGraphSeries(chart);
const node =
this._dragNode === undefined
? undefined
: series?.getGraph().getNodeById(this._dragNode);
if (
!chart ||
!node ||
!series.forceLayout ||
series.get(["force", "layoutAnimation"])
) {
return;
}
ev.cancelBubble = true;
const data = series.getData();
const el = data.getItemGraphicEl(node.dataIndex);
data.setItemLayout(node.dataIndex, [el.x, el.y]);
// A new layout run starts from here, e.g. after a legend change
if (series.preservedPoints) {
series.preservedPoints[node.id] = [el.x, el.y];
}
series.forceLayout.setFixed(node.dataIndex);
for (const edge of node.edges) {
const source: number[] | undefined = edge.node1.getLayout();
const target: number[] | undefined = edge.node2.getLayout();
// The nodes of hidden legend categories have no layout
if (source && target) {
edge.setLayout([[...source], [...target]]);
}
}
// @ts-ignore private method but no other way to draw the new layout
chart.getViewOfSeriesModel(series).updateLayout(series);
// The handlers of the chart miss the drag now
chart.getZr().handler.trigger("drag", ev);
};
private _handleDrag = () => {
this._dragMoved = true;
};
@@ -672,8 +617,6 @@ export class HaNetworkGraph extends LitElement {
const moved = this._dragMoved;
this._dragNode = undefined;
this._dragMoved = false;
this._dragTarget?.off("drag", this._handleNodeDrag);
this._dragTarget = undefined;
// A click also ends a drag, which releases a pinned node in ECharts
if (!id || (!moved && !this._pinnedNodes.includes(id))) {
return;
+1 -2
View File
@@ -1663,8 +1663,7 @@ export class HaDataTable extends LitElement {
}
.mdc-data-table__row ~ .mdc-data-table__row {
border-top: var(--data-table-row-border-width, 1px) solid
var(--divider-color);
border-top: 1px solid var(--divider-color);
}
.mdc-data-table__row.clickable:not(
+2 -14
View File
@@ -79,25 +79,13 @@ export const updateButtonIsDisabled = (entity: UpdateEntity): boolean =>
export const updateIsInstalling = (entity: UpdateEntity): boolean =>
!!entity.attributes.in_progress;
export interface UpdateReleaseNotesMessage {
severity: "info" | "warning" | "error";
message: string;
}
export interface UpdateReleaseNotes {
release_notes: string | null;
messages: UpdateReleaseNotesMessage[];
}
export const updateReleaseNotes = (
hass: Pick<HomeAssistant, "callWS">,
entityId: string,
language: string
entityId: string
) =>
hass.callWS<UpdateReleaseNotes>({
hass.callWS<string | null>({
type: "update/release_notes",
entity_id: entityId,
language,
});
const HOME_ASSISTANT_CORE_TITLE = "Home Assistant Core";
@@ -2,7 +2,6 @@ import type { ContextType } from "@lit/context";
import type { HassConfig, UnsubscribeFunc } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
import { consume } from "../../../common/decorators/consume";
import { BINARY_STATE_OFF } from "../../../common/const";
@@ -14,7 +13,6 @@ import { transform } from "../../../common/decorators/transform";
import { supportsFeature } from "../../../common/entity/supports-feature";
import type { LocalizeFunc } from "../../../common/translations/localize";
import { sanitizeHttpUrl } from "../../../common/url/sanitize-http-url";
import { estimateDirection } from "../../../common/util/estimate-direction";
import { closestWithProperty } from "../../../common/dom/ancestors-with-property";
import "../../../components/ha-alert";
import "../../../components/ha-button";
@@ -33,7 +31,7 @@ import {
} from "../../../data/context";
import { UNAVAILABLE, UNKNOWN } from "../../../data/entity/entity";
import type { EntityRegistryDisplayEntry } from "../../../data/entity/entity_registry";
import type { UpdateEntity, UpdateReleaseNotes } from "../../../data/update";
import type { UpdateEntity } from "../../../data/update";
import {
latestVersionIsSkipped,
updateButtonIsDisabled,
@@ -99,7 +97,7 @@ class MoreInfoUpdate extends LitElement {
})
private _user?: CurrentUser;
@state() private _releaseNotes?: UpdateReleaseNotes;
@state() private _releaseNotes?: string | null;
@state() private _error?: string;
@@ -263,41 +261,15 @@ class MoreInfoUpdate extends LitElement {
<hr />
${this._markdownLoading ? this._renderLoader() : nothing}
`
: this._releaseNotes.messages.length ||
this._releaseNotes.release_notes
: this._releaseNotes
? html`
<hr />
${this._releaseNotes.messages.map(
(message) => html`
<ha-alert
class="release-notes-message"
alert-type=${message.severity}
>
<ha-markdown
class=${classMap({
rtl: estimateDirection(message.message) === "rtl",
})}
.content=${message.message}
></ha-markdown>
</ha-alert>
`
)}
${
this._releaseNotes.release_notes
? html`
<ha-markdown
@content-resize=${this._markdownLoaded}
.content=${this._releaseNotes.release_notes}
class=${this._markdownLoading ? "hidden" : ""}
></ha-markdown>
${
this._markdownLoading
? this._renderLoader()
: nothing
}
`
: nothing
}
<ha-markdown
@content-resize=${this._markdownLoaded}
.content=${this._releaseNotes}
class=${this._markdownLoading ? "hidden" : ""}
></ha-markdown>
${this._markdownLoading ? this._renderLoader() : nothing}
`
: nothing
: this.stateObj.attributes.release_summary
@@ -421,8 +393,7 @@ class MoreInfoUpdate extends LitElement {
try {
this._releaseNotes = await updateReleaseNotes(
this._api,
this.stateObj!.entity_id,
this._i18n.language
this.stateObj!.entity_id
);
} catch (err: any) {
this._error = err.message;
@@ -612,11 +583,6 @@ class MoreInfoUpdate extends LitElement {
margin-bottom: var(--ha-space-4);
}
.release-notes-message {
display: block;
margin-bottom: var(--ha-space-4);
}
.row {
margin: 0;
display: flex;
@@ -676,12 +642,6 @@ class MoreInfoUpdate extends LitElement {
padding-bottom: var(--ha-space-4);
box-sizing: border-box;
}
.release-notes-message ha-markdown {
padding-bottom: 0;
}
ha-markdown.rtl {
direction: rtl;
}
ha-markdown.hidden {
display: none;
}
+19 -45
View File
@@ -2,7 +2,6 @@ import type { Auth, Connection } from "home-assistant-js-websocket";
import {
createConnection,
ERR_INVALID_AUTH,
ERR_INVALID_AUTH_CALLBACK,
getAuth,
subscribeConfig,
subscribeEntities,
@@ -37,30 +36,17 @@ declare global {
}
}
const replaceUrlParams = (searchParams: URLSearchParams) => {
const search = searchParams.toString();
history.replaceState(
null,
"",
`${location.pathname}${search ? `?${search}` : ""}`
);
};
const deleteAuthCallbackParams = (searchParams: URLSearchParams) => {
// https://github.com/home-assistant/home-assistant-js-websocket/blob/master/lib/auth.ts
// Remove all data from QueryCallbackData type
searchParams.delete("auth_callback");
searchParams.delete("code");
searchParams.delete("state");
searchParams.delete("storeToken");
};
const clearUrlParams = () => {
const searchParams = new URLSearchParams(location.search);
let changed = false;
// Clear auth data from url if we have been able to establish a connection
if (location.search.includes("auth_callback=1")) {
deleteAuthCallbackParams(searchParams);
// https://github.com/home-assistant/home-assistant-js-websocket/blob/master/lib/auth.ts
// Remove all data from QueryCallbackData type
searchParams.delete("auth_callback");
searchParams.delete("code");
searchParams.delete("state");
searchParams.delete("storeToken");
changed = true;
}
// Remove the cache-busting param added by the stale-index recovery guard in
@@ -71,30 +57,12 @@ const clearUrlParams = () => {
changed = true;
}
if (changed) {
replaceUrlParams(searchParams);
}
};
const authOptions = {
hassUrl,
limitHassInstance: true,
saveTokens,
loadTokens: () => Promise.resolve(loadTokens()),
};
const getAuthDroppingStaleCallback = async () => {
try {
return await getAuth(authOptions);
} catch (err: unknown) {
if (err !== ERR_INVALID_AUTH && err !== ERR_INVALID_AUTH_CALLBACK) {
throw err;
}
// The auth callback in the URL was used or has expired. Drop it so a
// reload does not replay it, and fall back to stored tokens or a new login.
const searchParams = new URLSearchParams(location.search);
deleteAuthCallbackParams(searchParams);
replaceUrlParams(searchParams);
return getAuth(authOptions);
const search = searchParams.toString();
history.replaceState(
null,
"",
`${location.pathname}${search ? `?${search}` : ""}`
);
}
};
@@ -103,7 +71,13 @@ const authProm = isExternal
import("../external_app/external_auth").then(({ createExternalAuth }) =>
createExternalAuth(hassUrl)
)
: getAuthDroppingStaleCallback;
: () =>
getAuth({
hassUrl,
limitHassInstance: true,
saveTokens,
loadTokens: () => Promise.resolve(loadTokens()),
});
const connProm = async (auth) => {
try {
+18 -7
View File
@@ -233,7 +233,12 @@ export class HassTabsSubpage extends LitElement {
}
${
this.showTabs && !this._narrow
? html`<div id="tabbar">${tabs}</div>`
? html`<nav
id="tabbar"
aria-label=${localize("ui.common.subpage_tabs")}
>
${tabs}
</nav>`
: ""
}
<div id="toolbar-icon">
@@ -241,11 +246,6 @@ export class HassTabsSubpage extends LitElement {
</div>
</div>
</slot>
${
this.showTabs && this._narrow
? html`<div id="tabbar" class="bottom-bar">${tabs}</div>`
: ""
}
</div>
<div class="container">
${
@@ -271,6 +271,17 @@ export class HassTabsSubpage extends LitElement {
<div id="fab">
<slot name="fab"></slot>
</div>
${
this.showTabs && this._narrow
? html`<nav
id="tabbar"
class="bottom-bar"
aria-label=${localize("ui.common.subpage_tabs")}
>
${tabs}
</nav>`
: nothing
}
`;
}
@@ -401,7 +412,7 @@ export class HassTabsSubpage extends LitElement {
:host([narrow]) .toolbar-content {
padding: 4px;
}
.toolbar a {
#tabbar a {
color: var(--sidebar-text-color);
text-decoration: none;
}
@@ -1,7 +1,6 @@
import type { TemplateResult } from "lit";
import { LitElement, css, html } from "lit";
import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import { consume } from "../common/decorators/consume";
import "../components/ha-card";
import "../components/ha-ripple";
@@ -24,7 +23,6 @@ class OnboardingWelcomeLink extends LitElement {
protected render(): TemplateResult {
return html`
<ha-card
role=${ifDefined(this.noninteractive ? undefined : "button")}
.tabIndex=${this.noninteractive ? "-1" : "0"}
@keydown=${this._handleKeyDown}
>
@@ -37,7 +35,6 @@ class OnboardingWelcomeLink extends LitElement {
private _handleKeyDown(ev: KeyboardEvent): void {
if (ev.key === "Enter" || ev.key === " ") {
ev.preventDefault();
(ev.target as HTMLElement).click();
}
}
@@ -221,7 +221,9 @@ const computeDeviceClassOptions = (
const groups: string[][] = OVERRIDE_DEVICE_CLASSES[domain];
for (const group of groups) {
if (originalDeviceClass && group.includes(originalDeviceClass)) {
related.push(...group);
related.push(
...group.filter((deviceClass) => deviceClass !== originalDeviceClass)
);
} else {
others.push(...group);
}
@@ -343,7 +345,10 @@ export class EntityRegistrySettingsEditor extends LitElement {
this._name = this.entry.name || this._originalName;
this._isMainEntity = !!this._device && !this._entryName;
this._icon = this.entry.icon || "";
this._deviceClass = this.entry.device_class ?? null;
this._deviceClass =
this.entry.device_class === this._originalDeviceClass
? null
: (this.entry.device_class ?? null);
this._origEntityId = this.entry.entity_id;
this._areaId = this.entry.area_id;
this._mainEntityWithOwnArea = this._isMainEntity && !!this.entry.area_id;
@@ -5,7 +5,6 @@ import {
mdiNas,
mdiPencil,
mdiPlayBox,
mdiRefresh,
mdiReload,
} from "@mdi/js";
import type { PropertyValues, TemplateResult } from "lit";
@@ -33,8 +32,6 @@ import {
fetchHassioHostInfo,
fetchHostDisksUsage,
} from "../../../data/hassio/host";
import type { RecorderDatabaseUsage } from "../../../data/recorder";
import { fetchRecorderDatabaseUsage } from "../../../data/recorder";
import type {
SupervisorMount,
SupervisorMounts,
@@ -80,17 +77,6 @@ class HaConfigSectionStorage extends LitElement {
// Guards against a slow response from a previous reload landing in a newer one.
private _mountUsageGeneration = 0;
// Undefined until loaded, null when no recent report exists.
@state() private _databaseUsage?: RecorderDatabaseUsage | null;
@state() private _databaseLoading = false;
@state() private _databaseAnalyzing = false;
@state() private _databaseError?: string;
private _databaseRequested = false;
protected async firstUpdated(
changedProps: PropertyValues<this>
): Promise<void> {
@@ -103,19 +89,6 @@ class HaConfigSectionStorage extends LitElement {
await panelIsReady(this);
}
protected willUpdate(changedProps: PropertyValues<this>): void {
super.willUpdate(changedProps);
// Recorder can finish loading after the page mounted during startup
if (
changedProps.has("hass") &&
!this._databaseRequested &&
isComponentLoaded(this.hass.config, "recorder")
) {
this._databaseRequested = true;
this._loadDatabaseUsage();
}
}
protected render(): TemplateResult | typeof nothing {
if (this._mountsInfo === undefined) {
return nothing;
@@ -128,7 +101,6 @@ class HaConfigSectionStorage extends LitElement {
].includes(mount.type)
);
const isHAOS = this._hostInfo?.features.includes("haos");
const hasRecorder = isComponentLoaded(this.hass.config, "recorder");
return html`
<hass-subpage
back-path="/config/system"
@@ -136,19 +108,6 @@ class HaConfigSectionStorage extends LitElement {
.narrow=${this.narrow}
.header=${this.hass.localize("ui.panel.config.storage.caption")}
>
${
hasRecorder
? html`<ha-icon-button
slot="toolbar-icon"
.disabled=${this._databaseLoading || this._databaseAnalyzing}
.path=${mdiRefresh}
.label=${this.hass.localize(
"ui.panel.config.storage.database.analyze"
)}
@click=${this._analyzeDatabase}
></ha-icon-button>`
: nothing
}
<div class="content">
${
this._error
@@ -195,12 +154,9 @@ class HaConfigSectionStorage extends LitElement {
: ""
}
${
hasRecorder
isComponentLoaded(this.hass.config, "recorder")
? html`<storage-database-card
.narrow=${this.narrow}
.usage=${this._databaseUsage}
.analyzing=${this._databaseAnalyzing}
.error=${this._databaseError}
></storage-database-card>`
: nothing
}
@@ -440,45 +396,6 @@ class HaConfigSectionStorage extends LitElement {
}
}
private async _loadDatabaseUsage(): Promise<void> {
this._databaseLoading = true;
this._databaseError = undefined;
try {
this._databaseUsage = await fetchRecorderDatabaseUsage(this.hass);
} catch (err: any) {
this._databaseError = this._databaseErrorMessage(err);
} finally {
this._databaseLoading = false;
}
}
private async _analyzeDatabase(): Promise<void> {
this._databaseAnalyzing = true;
this._databaseError = undefined;
try {
this._databaseUsage = await fetchRecorderDatabaseUsage(this.hass, true);
} catch (err: any) {
this._databaseError = this._databaseErrorMessage(err);
} finally {
this._databaseAnalyzing = false;
}
}
private _databaseErrorMessage(err: any): string {
switch (err.code) {
case "recorder_not_ready":
return this.hass.localize(
"ui.panel.config.storage.database.errors.recorder_not_ready"
);
case "migration_in_progress":
return this.hass.localize(
"ui.panel.config.storage.database.errors.migration_in_progress"
);
default:
return err.message || err.code || String(err);
}
}
private _moveDatadisk(): void {
showMoveDatadiskDialog(this, {
hostInfo: this._hostInfo!,
@@ -1,4 +1,4 @@
import type { TemplateResult } from "lit";
import type { PropertyValues, TemplateResult } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import type { HassConfig } from "home-assistant-js-websocket";
@@ -18,11 +18,13 @@ import type {
DataTableRowData,
} from "../../../components/data-table/ha-data-table";
import "../../../components/ha-alert";
import "../../../components/ha-button";
import "../../../components/ha-card";
import "../../../components/ha-segmented-bar";
import type { Segment } from "../../../components/ha-segmented-bar";
import "../../../components/ha-spinner";
import {
apiContext,
configContext,
fullEntitiesContext,
internationalizationContext,
@@ -34,11 +36,13 @@ import type {
RecorderTableUsage,
} from "../../../data/recorder";
import type { EntityRegistryEntry } from "../../../data/entity/entity_registry";
import { fetchRecorderDatabaseUsage } from "../../../data/recorder";
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
import type { FrontendLocaleData } from "../../../data/translation";
import type { Themes } from "../../../data/ws-themes";
import type {
HomeAssistant,
HomeAssistantApi,
HomeAssistantConfig,
HomeAssistantInternationalization,
HomeAssistantUI,
@@ -122,13 +126,6 @@ interface EntityUsageRow extends DatabaseUsageRow, DataTableRowData {
export class StorageDatabaseCard extends LitElement {
@property({ type: Boolean }) public narrow = false;
// Undefined until loaded, null when no recent report exists.
@property({ attribute: false }) public usage?: RecorderDatabaseUsage | null;
@property({ type: Boolean }) public analyzing = false;
@property() public error?: string;
@state()
@consumeLocalize()
private _localize!: LocalizeFunc;
@@ -147,6 +144,9 @@ export class StorageDatabaseCard extends LitElement {
})
private _hassConfig!: HassConfig;
@consume({ context: apiContext, subscribe: true })
private _api!: HomeAssistantApi;
@state()
@consume({ context: uiContext, subscribe: true })
@transform<HomeAssistantUI, Themes>({
@@ -163,8 +163,22 @@ export class StorageDatabaseCard extends LitElement {
@consume({ context: fullEntitiesContext, subscribe: true })
private _entityRegistry: EntityRegistryEntry[] = [];
// Undefined until loaded, null when no recent report exists.
@state() private _usage?: RecorderDatabaseUsage | null;
@state() private _loading = false;
@state() private _analyzing = false;
@state() private _error?: string;
protected firstUpdated(changedProps: PropertyValues<this>): void {
super.firstUpdated(changedProps);
this._load();
}
protected render(): TemplateResult {
const usage = this.usage;
const usage = this._usage;
return html`
<ha-card
outlined
@@ -172,34 +186,45 @@ export class StorageDatabaseCard extends LitElement {
>
<div class="card-content">
${
this.error
? html`<ha-alert alert-type="error">${this.error}</ha-alert>`
: nothing
}
${
this.analyzing
? html`<div class="loading">
<ha-spinner></ha-spinner>
<span>
${this._localize(
"ui.panel.config.storage.database.analyzing"
)}
</span>
</div>`
this._error
? html`<ha-alert alert-type="error">${this._error}</ha-alert>`
: nothing
}
${
usage
? this._renderUsage(usage)
: usage === null && !this.analyzing
? html`<p class="description">
${this._localize(
"ui.panel.config.storage.database.description"
)}
</p>`
: nothing
: this._analyzing
? html`<div class="loading">
<ha-spinner></ha-spinner>
<span>
${this._localize(
"ui.panel.config.storage.database.analyzing"
)}
</span>
</div>`
: usage === null
? html`<p class="description">
${this._localize(
"ui.panel.config.storage.database.description"
)}
</p>`
: nothing
}
</div>
<div class="card-actions">
<ha-button
appearance="plain"
.loading=${this._analyzing}
.disabled=${this._loading || this._analyzing}
@click=${this._analyze}
>
${this._localize(
usage
? "ui.panel.config.storage.database.analyze_again"
: "ui.panel.config.storage.database.analyze"
)}
</ha-button>
</div>
</ha-card>
`;
}
@@ -443,6 +468,45 @@ export class StorageDatabaseCard extends LitElement {
});
};
private async _load() {
this._loading = true;
this._error = undefined;
try {
this._usage = await fetchRecorderDatabaseUsage(this._api);
} catch (err: any) {
this._error = this._errorMessage(err);
} finally {
this._loading = false;
}
}
private async _analyze() {
this._analyzing = true;
this._error = undefined;
try {
this._usage = await fetchRecorderDatabaseUsage(this._api, true);
} catch (err: any) {
this._error = this._errorMessage(err);
} finally {
this._analyzing = false;
}
}
private _errorMessage(err: any): string {
switch (err.code) {
case "recorder_not_ready":
return this._localize(
"ui.panel.config.storage.database.errors.recorder_not_ready"
);
case "migration_in_progress":
return this._localize(
"ui.panel.config.storage.database.errors.migration_in_progress"
);
default:
return err.message || err.code || String(err);
}
}
static styles = css`
ha-card {
margin-bottom: 12px;
@@ -452,6 +516,10 @@ export class StorageDatabaseCard extends LitElement {
flex-direction: column;
gap: var(--ha-space-4);
}
.card-actions {
display: flex;
justify-content: flex-end;
}
.loading {
display: flex;
align-items: center;
@@ -479,7 +547,6 @@ export class StorageDatabaseCard extends LitElement {
}
ha-data-table {
--data-table-border-width: 0;
--data-table-row-border-width: 0;
height: 100%;
}
`;
-5
View File
@@ -277,12 +277,7 @@ export const getMyRedirects = (): Redirects => ({
config: {
redirect: "/config/dashboard",
},
link: {
component: "cloud",
redirect: "/config/cloud",
},
cloud: {
// Old key of link, still used by existing links and my.home-assistant.io
component: "cloud",
redirect: "/config/cloud",
},
+5 -3
View File
@@ -542,7 +542,8 @@
"markdown": "Markdown",
"none": "None",
"first": "First",
"last": "Last"
"last": "Last",
"subpage_tabs": "Pages"
},
"components": {
"safe_area_tool": {
@@ -10003,9 +10004,10 @@
"change_chart_type": "Change chart type",
"database": {
"title": "Database",
"description": "Use the refresh button to analyze the database and see which tables, entities and statistics use the most space.",
"description": "Analyze the database to see which tables, entities and statistics use the most space.",
"analyzing": "Analyzing the database, this can take a while on a large database...",
"analyze": "Analyze database",
"analyze": "Analyze",
"analyze_again": "Analyze again",
"as_of": "as of {time}",
"tables": "Tables",
"other_tables": "Other tables",