diff --git a/src/data/entity_registry.ts b/src/data/entity_registry.ts index 4c5271e82d..98ff504f22 100644 --- a/src/data/entity_registry.ts +++ b/src/data/entity_registry.ts @@ -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 -): Promise => +): Promise => hass.callWS({ type: "config/entity_registry/update", entity_id: entityId, diff --git a/src/panels/config/entities/entity-registry-basic-editor.ts b/src/panels/config/entities/entity-registry-basic-editor.ts index 4b4ac7723d..79d4bcb07b 100644 --- a/src/panels/config/entities/entity-registry-basic-editor.ts +++ b/src/panels/config/entities/entity-registry-basic-editor.ts @@ -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; } diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index e6b7ea577d..0912c6331f 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -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"; diff --git a/src/panels/config/entities/ha-config-entities.ts b/src/panels/config/entities/ha-config-entities.ts index 85ffc4a26a..e13e688026 100644 --- a/src/panels/config/entities/ha-config-entities.ts +++ b/src/panels/config/entities/ha-config-entities.ts @@ -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 + ), + }); + } }, }); } diff --git a/src/translations/en.json b/src/translations/en.json index 98e7eabaa0..8c20dcf744 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -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",