mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 10:16:46 +00:00
Merge pull request #11716 from emontnemery/remove_config_entry_from_device
Add support for removing config entry from a device
This commit is contained in:
commit
794bc161c8
@ -29,6 +29,7 @@ const createConfigEntry = (
|
|||||||
source: "zeroconf",
|
source: "zeroconf",
|
||||||
state: "loaded",
|
state: "loaded",
|
||||||
supports_options: false,
|
supports_options: false,
|
||||||
|
supports_remove_device: false,
|
||||||
supports_unload: true,
|
supports_unload: true,
|
||||||
disabled_by: null,
|
disabled_by: null,
|
||||||
pref_disable_new_entities: false,
|
pref_disable_new_entities: false,
|
||||||
|
@ -13,6 +13,7 @@ export interface ConfigEntry {
|
|||||||
| "not_loaded"
|
| "not_loaded"
|
||||||
| "failed_unload";
|
| "failed_unload";
|
||||||
supports_options: boolean;
|
supports_options: boolean;
|
||||||
|
supports_remove_device: boolean;
|
||||||
supports_unload: boolean;
|
supports_unload: boolean;
|
||||||
pref_disable_new_entities: boolean;
|
pref_disable_new_entities: boolean;
|
||||||
pref_disable_polling: boolean;
|
pref_disable_polling: boolean;
|
||||||
|
@ -77,6 +77,17 @@ export const updateDeviceRegistryEntry = (
|
|||||||
...updates,
|
...updates,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const removeConfigEntryFromDevice = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
deviceId: string,
|
||||||
|
configEntryId: string
|
||||||
|
) =>
|
||||||
|
hass.callWS<DeviceRegistryEntry>({
|
||||||
|
type: "config/device_registry/remove_config_entry",
|
||||||
|
device_id: deviceId,
|
||||||
|
config_entry_id: configEntryId,
|
||||||
|
});
|
||||||
|
|
||||||
export const fetchDeviceRegistry = (conn) =>
|
export const fetchDeviceRegistry = (conn) =>
|
||||||
conn.sendMessagePromise({
|
conn.sendMessagePromise({
|
||||||
type: "config/device_registry/list",
|
type: "config/device_registry/list",
|
||||||
|
@ -27,6 +27,7 @@ import {
|
|||||||
computeDeviceName,
|
computeDeviceName,
|
||||||
DeviceRegistryEntry,
|
DeviceRegistryEntry,
|
||||||
updateDeviceRegistryEntry,
|
updateDeviceRegistryEntry,
|
||||||
|
removeConfigEntryFromDevice,
|
||||||
} from "../../../data/device_registry";
|
} from "../../../data/device_registry";
|
||||||
import {
|
import {
|
||||||
fetchDiagnosticHandler,
|
fetchDiagnosticHandler,
|
||||||
@ -95,6 +96,8 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
| number
|
| number
|
||||||
| (TemplateResult | string)[];
|
| (TemplateResult | string)[];
|
||||||
|
|
||||||
|
@state() private _deleteButtons?: (TemplateResult | string)[];
|
||||||
|
|
||||||
private _device = memoizeOne(
|
private _device = memoizeOne(
|
||||||
(
|
(
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
@ -186,10 +189,11 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
changedProps.has("entries")
|
changedProps.has("entries")
|
||||||
) {
|
) {
|
||||||
this._diagnosticDownloadLinks = undefined;
|
this._diagnosticDownloadLinks = undefined;
|
||||||
|
this._deleteButtons = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this._diagnosticDownloadLinks ||
|
(this._diagnosticDownloadLinks && this._deleteButtons) ||
|
||||||
!this.devices ||
|
!this.devices ||
|
||||||
!this.deviceId ||
|
!this.deviceId ||
|
||||||
!this.entries
|
!this.entries
|
||||||
@ -198,7 +202,9 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._diagnosticDownloadLinks = Math.random();
|
this._diagnosticDownloadLinks = Math.random();
|
||||||
|
this._deleteButtons = []; // To prevent re-rendering if no delete buttons
|
||||||
this._renderDiagnosticButtons(this._diagnosticDownloadLinks);
|
this._renderDiagnosticButtons(this._diagnosticDownloadLinks);
|
||||||
|
this._renderDeleteButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _renderDiagnosticButtons(requestId: number): Promise<void> {
|
private async _renderDiagnosticButtons(requestId: number): Promise<void> {
|
||||||
@ -263,6 +269,55 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _renderDeleteButtons() {
|
||||||
|
const device = this._device(this.deviceId, this.devices);
|
||||||
|
|
||||||
|
if (!device) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const buttons: TemplateResult[] = [];
|
||||||
|
this._integrations(device, this.entries).forEach((entry) => {
|
||||||
|
if (entry.state !== "loaded" || !entry.supports_remove_device) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
buttons.push(html`
|
||||||
|
<mwc-button
|
||||||
|
class="warning"
|
||||||
|
.entryId=${entry.entry_id}
|
||||||
|
@click=${this._confirmDeleteEntry}
|
||||||
|
>
|
||||||
|
${buttons.length > 1
|
||||||
|
? this.hass.localize(
|
||||||
|
`ui.panel.config.devices.delete_device_integration`,
|
||||||
|
{
|
||||||
|
integration: domainToName(this.hass.localize, entry.domain),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
: this.hass.localize(`ui.panel.config.devices.delete_device`)}
|
||||||
|
</mwc-button>
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (buttons.length > 0) {
|
||||||
|
this._deleteButtons = buttons;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _confirmDeleteEntry(e: MouseEvent): Promise<void> {
|
||||||
|
const entryId = (e.currentTarget as any).entryId;
|
||||||
|
|
||||||
|
const confirmed = await showConfirmationDialog(this, {
|
||||||
|
text: this.hass.localize("ui.panel.config.devices.confirm_delete"),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!confirmed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await removeConfigEntryFromDevice(this.hass!, this.deviceId, entryId);
|
||||||
|
}
|
||||||
|
|
||||||
protected firstUpdated(changedProps) {
|
protected firstUpdated(changedProps) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
loadDeviceRegistryDetailDialog();
|
loadDeviceRegistryDetailDialog();
|
||||||
@ -375,6 +430,9 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
if (Array.isArray(this._diagnosticDownloadLinks)) {
|
if (Array.isArray(this._diagnosticDownloadLinks)) {
|
||||||
deviceActions.push(...this._diagnosticDownloadLinks);
|
deviceActions.push(...this._diagnosticDownloadLinks);
|
||||||
}
|
}
|
||||||
|
if (this._deleteButtons) {
|
||||||
|
deviceActions.push(...this._deleteButtons);
|
||||||
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hass-tabs-subpage
|
<hass-tabs-subpage
|
||||||
|
@ -2287,6 +2287,8 @@
|
|||||||
"open_configuration_url_service": "Visit service",
|
"open_configuration_url_service": "Visit service",
|
||||||
"download_diagnostics": "Download diagnostics",
|
"download_diagnostics": "Download diagnostics",
|
||||||
"download_diagnostics_integration": "Download {integration} diagnostics",
|
"download_diagnostics_integration": "Download {integration} diagnostics",
|
||||||
|
"delete_device": "Delete device",
|
||||||
|
"delete_device_integration": "Remove {integration} from device",
|
||||||
"type": {
|
"type": {
|
||||||
"device_heading": "Device",
|
"device_heading": "Device",
|
||||||
"device": "device",
|
"device": "device",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user