mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
Improve user experience when enabling a disabled entity (#7580)
This commit is contained in:
parent
6e336dd207
commit
129f9c147b
@ -20,6 +20,12 @@ export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
|
||||
original_icon?: string;
|
||||
}
|
||||
|
||||
export interface UpdateEntityRegistryEntryResult {
|
||||
entity_entry: ExtEntityRegistryEntry;
|
||||
reload_delay?: number;
|
||||
require_restart?: boolean;
|
||||
}
|
||||
|
||||
export interface EntityRegistryEntryUpdateParams {
|
||||
name?: string | null;
|
||||
icon?: string | null;
|
||||
@ -72,7 +78,7 @@ export const updateEntityRegistryEntry = (
|
||||
hass: HomeAssistant,
|
||||
entityId: string,
|
||||
updates: Partial<EntityRegistryEntryUpdateParams>
|
||||
): Promise<ExtEntityRegistryEntry> =>
|
||||
): Promise<UpdateEntityRegistryEntryResult> =>
|
||||
hass.callWS({
|
||||
type: "config/entity_registry/update",
|
||||
entity_id: entityId,
|
||||
|
@ -17,6 +17,7 @@ import {
|
||||
ExtEntityRegistryEntry,
|
||||
updateEntityRegistryEntry,
|
||||
} from "../../../data/entity_registry";
|
||||
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||
import type { PolymerChangedEvent } from "../../../polymer-types";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
|
||||
@ -43,7 +44,27 @@ export class HaEntityRegistryBasicEditor extends LitElement {
|
||||
params.disabled_by = this._disabledBy;
|
||||
}
|
||||
try {
|
||||
await updateEntityRegistryEntry(this.hass!, this._origEntityId, params);
|
||||
const result = await updateEntityRegistryEntry(
|
||||
this.hass!,
|
||||
this._origEntityId,
|
||||
params
|
||||
);
|
||||
if (result.require_restart) {
|
||||
showAlertDialog(this, {
|
||||
text: this.hass.localize(
|
||||
"ui.dialogs.entity_registry.editor.enabled_restart_confirm"
|
||||
),
|
||||
});
|
||||
}
|
||||
if (result.reload_delay) {
|
||||
showAlertDialog(this, {
|
||||
text: this.hass.localize(
|
||||
"ui.dialogs.entity_registry.editor.enabled_delay_confirm",
|
||||
"delay",
|
||||
result.reload_delay
|
||||
),
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
this._submitting = false;
|
||||
}
|
||||
|
@ -23,7 +23,10 @@ import {
|
||||
removeEntityRegistryEntry,
|
||||
updateEntityRegistryEntry,
|
||||
} from "../../../data/entity_registry";
|
||||
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||
import {
|
||||
showAlertDialog,
|
||||
showConfirmationDialog,
|
||||
} from "../../../dialogs/generic/show-dialog-box";
|
||||
import type { PolymerChangedEvent } from "../../../polymer-types";
|
||||
import { haStyle } from "../../../resources/styles";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
@ -191,7 +194,27 @@ export class EntityRegistrySettings extends LitElement {
|
||||
params.disabled_by = this._disabledBy;
|
||||
}
|
||||
try {
|
||||
await updateEntityRegistryEntry(this.hass!, this._origEntityId, params);
|
||||
const result = await updateEntityRegistryEntry(
|
||||
this.hass!,
|
||||
this._origEntityId,
|
||||
params
|
||||
);
|
||||
if (result.require_restart) {
|
||||
showAlertDialog(this, {
|
||||
text: this.hass.localize(
|
||||
"ui.dialogs.entity_registry.editor.enabled_restart_confirm"
|
||||
),
|
||||
});
|
||||
}
|
||||
if (result.reload_delay) {
|
||||
showAlertDialog(this, {
|
||||
text: this.hass.localize(
|
||||
"ui.dialogs.entity_registry.editor.enabled_delay_confirm",
|
||||
"delay",
|
||||
result.reload_delay
|
||||
),
|
||||
});
|
||||
}
|
||||
fireEvent(this as HTMLElement, "close-dialog");
|
||||
} catch (err) {
|
||||
this._error = err.message || "Unknown error";
|
||||
|
@ -46,7 +46,10 @@ import {
|
||||
updateEntityRegistryEntry,
|
||||
} from "../../../data/entity_registry";
|
||||
import { domainToName } from "../../../data/integration";
|
||||
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||
import {
|
||||
showAlertDialog,
|
||||
showConfirmationDialog,
|
||||
} from "../../../dialogs/generic/show-dialog-box";
|
||||
import "../../../layouts/hass-loading-screen";
|
||||
import "../../../layouts/hass-tabs-subpage-data-table";
|
||||
import type { HaTabsSubpageDataTable } from "../../../layouts/hass-tabs-subpage-data-table";
|
||||
@ -685,7 +688,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
|
||||
this._selectedEntities = ev.detail.value;
|
||||
}
|
||||
|
||||
private _enableSelected() {
|
||||
private async _enableSelected() {
|
||||
showConfirmationDialog(this, {
|
||||
title: this.hass.localize(
|
||||
"ui.panel.config.entities.picker.enable_selected.confirm_title",
|
||||
@ -697,13 +700,40 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
|
||||
),
|
||||
confirmText: this.hass.localize("ui.common.yes"),
|
||||
dismissText: this.hass.localize("ui.common.no"),
|
||||
confirm: () => {
|
||||
this._selectedEntities.forEach((entity) =>
|
||||
updateEntityRegistryEntry(this.hass, entity, {
|
||||
disabled_by: null,
|
||||
confirm: async () => {
|
||||
let require_restart = false;
|
||||
let reload_delay = 0;
|
||||
await Promise.all(
|
||||
this._selectedEntities.map(async (entity) => {
|
||||
const result = await updateEntityRegistryEntry(this.hass, entity, {
|
||||
disabled_by: null,
|
||||
});
|
||||
if (result.require_restart) {
|
||||
require_restart = true;
|
||||
}
|
||||
if (result.reload_delay) {
|
||||
reload_delay = Math.max(reload_delay, result.reload_delay);
|
||||
}
|
||||
})
|
||||
);
|
||||
this._clearSelection();
|
||||
// If restart is required by any entity, show a dialog.
|
||||
// Otherwise, show a dialog explaining that some patience is needed
|
||||
if (require_restart) {
|
||||
showAlertDialog(this, {
|
||||
text: this.hass.localize(
|
||||
"ui.dialogs.entity_registry.editor.enabled_restart_confirm"
|
||||
),
|
||||
});
|
||||
} else if (reload_delay) {
|
||||
showAlertDialog(this, {
|
||||
text: this.hass.localize(
|
||||
"ui.dialogs.entity_registry.editor.enabled_delay_confirm",
|
||||
"delay",
|
||||
reload_delay
|
||||
),
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -577,6 +577,8 @@
|
||||
"enabled_label": "Enable entity",
|
||||
"enabled_cause": "Disabled by {cause}.",
|
||||
"enabled_description": "Disabled entities will not be added to Home Assistant.",
|
||||
"enabled_delay_confirm": "The enabled entities will be added to Home Assistant in {delay} seconds",
|
||||
"enabled_restart_confirm": "Restart Home Assistant to finish enabling the entities",
|
||||
"delete": "Delete",
|
||||
"confirm_delete": "Are you sure you want to delete this entry?",
|
||||
"update": "Update",
|
||||
|
Loading…
x
Reference in New Issue
Block a user