Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/data/entity_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 22 additions & 1 deletion src/panels/config/entities/entity-registry-basic-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;
}
Expand Down
27 changes: 25 additions & 2 deletions src/panels/config/entities/entity-registry-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
42 changes: 36 additions & 6 deletions src/panels/config/entities/ha-config-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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",
Expand All @@ -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
),
});
}
},
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,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",
Expand Down