mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +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;
|
original_icon?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UpdateEntityRegistryEntryResult {
|
||||||
|
entity_entry: ExtEntityRegistryEntry;
|
||||||
|
reload_delay?: number;
|
||||||
|
require_restart?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface EntityRegistryEntryUpdateParams {
|
export interface EntityRegistryEntryUpdateParams {
|
||||||
name?: string | null;
|
name?: string | null;
|
||||||
icon?: string | null;
|
icon?: string | null;
|
||||||
@ -72,7 +78,7 @@ export const updateEntityRegistryEntry = (
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entityId: string,
|
entityId: string,
|
||||||
updates: Partial<EntityRegistryEntryUpdateParams>
|
updates: Partial<EntityRegistryEntryUpdateParams>
|
||||||
): Promise<ExtEntityRegistryEntry> =>
|
): Promise<UpdateEntityRegistryEntryResult> =>
|
||||||
hass.callWS({
|
hass.callWS({
|
||||||
type: "config/entity_registry/update",
|
type: "config/entity_registry/update",
|
||||||
entity_id: entityId,
|
entity_id: entityId,
|
||||||
|
@ -17,6 +17,7 @@ import {
|
|||||||
ExtEntityRegistryEntry,
|
ExtEntityRegistryEntry,
|
||||||
updateEntityRegistryEntry,
|
updateEntityRegistryEntry,
|
||||||
} from "../../../data/entity_registry";
|
} from "../../../data/entity_registry";
|
||||||
|
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||||
import type { PolymerChangedEvent } from "../../../polymer-types";
|
import type { PolymerChangedEvent } from "../../../polymer-types";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
|
|
||||||
@ -43,7 +44,27 @@ export class HaEntityRegistryBasicEditor extends LitElement {
|
|||||||
params.disabled_by = this._disabledBy;
|
params.disabled_by = this._disabledBy;
|
||||||
}
|
}
|
||||||
try {
|
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 {
|
} finally {
|
||||||
this._submitting = false;
|
this._submitting = false;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,10 @@ import {
|
|||||||
removeEntityRegistryEntry,
|
removeEntityRegistryEntry,
|
||||||
updateEntityRegistryEntry,
|
updateEntityRegistryEntry,
|
||||||
} from "../../../data/entity_registry";
|
} 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 type { PolymerChangedEvent } from "../../../polymer-types";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
@ -191,7 +194,27 @@ export class EntityRegistrySettings extends LitElement {
|
|||||||
params.disabled_by = this._disabledBy;
|
params.disabled_by = this._disabledBy;
|
||||||
}
|
}
|
||||||
try {
|
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");
|
fireEvent(this as HTMLElement, "close-dialog");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._error = err.message || "Unknown error";
|
this._error = err.message || "Unknown error";
|
||||||
|
@ -46,7 +46,10 @@ import {
|
|||||||
updateEntityRegistryEntry,
|
updateEntityRegistryEntry,
|
||||||
} from "../../../data/entity_registry";
|
} from "../../../data/entity_registry";
|
||||||
import { domainToName } from "../../../data/integration";
|
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-loading-screen";
|
||||||
import "../../../layouts/hass-tabs-subpage-data-table";
|
import "../../../layouts/hass-tabs-subpage-data-table";
|
||||||
import type { HaTabsSubpageDataTable } from "../../../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;
|
this._selectedEntities = ev.detail.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _enableSelected() {
|
private async _enableSelected() {
|
||||||
showConfirmationDialog(this, {
|
showConfirmationDialog(this, {
|
||||||
title: this.hass.localize(
|
title: this.hass.localize(
|
||||||
"ui.panel.config.entities.picker.enable_selected.confirm_title",
|
"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"),
|
confirmText: this.hass.localize("ui.common.yes"),
|
||||||
dismissText: this.hass.localize("ui.common.no"),
|
dismissText: this.hass.localize("ui.common.no"),
|
||||||
confirm: () => {
|
confirm: async () => {
|
||||||
this._selectedEntities.forEach((entity) =>
|
let require_restart = false;
|
||||||
updateEntityRegistryEntry(this.hass, entity, {
|
let reload_delay = 0;
|
||||||
|
await Promise.all(
|
||||||
|
this._selectedEntities.map(async (entity) => {
|
||||||
|
const result = await updateEntityRegistryEntry(this.hass, entity, {
|
||||||
disabled_by: null,
|
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();
|
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_label": "Enable entity",
|
||||||
"enabled_cause": "Disabled by {cause}.",
|
"enabled_cause": "Disabled by {cause}.",
|
||||||
"enabled_description": "Disabled entities will not be added to Home Assistant.",
|
"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",
|
"delete": "Delete",
|
||||||
"confirm_delete": "Are you sure you want to delete this entry?",
|
"confirm_delete": "Are you sure you want to delete this entry?",
|
||||||
"update": "Update",
|
"update": "Update",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user