From c50cf78bb4a3b4a9f0ba8bb9b8de5dc0739583a5 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Mon, 11 Jul 2022 14:14:37 -0400 Subject: [PATCH] Allow stale ZHA coordinator entries to be deleted (#13154) Co-authored-by: Bram Kragten --- src/data/zha.ts | 1 + .../zha/device-actions.ts | 82 +++++++++---------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/data/zha.ts b/src/data/zha.ts index d1b6f2ab97..247f1f1827 100644 --- a/src/data/zha.ts +++ b/src/data/zha.ts @@ -26,6 +26,7 @@ export interface ZHADevice { power_source?: string; area_id?: string; device_type: string; + active_coordinator: boolean; signature: any; neighbors: Neighbor[]; pairing_status?: string; diff --git a/src/panels/config/devices/device-detail/integration-elements/zha/device-actions.ts b/src/panels/config/devices/device-detail/integration-elements/zha/device-actions.ts index 476ff74993..5685b053d4 100644 --- a/src/panels/config/devices/device-detail/integration-elements/zha/device-actions.ts +++ b/src/panels/config/devices/device-detail/integration-elements/zha/device-actions.ts @@ -30,7 +30,7 @@ export const getZHADeviceActions = async ( const actions: DeviceAction[] = []; - if (zhaDevice.device_type !== "Coordinator") { + if (!zhaDevice.active_coordinator) { actions.push({ label: hass.localize("ui.dialogs.zha_device_info.buttons.reconfigure"), action: () => showZHAReconfigureDeviceDialog(el, { device: zhaDevice }), @@ -58,50 +58,50 @@ export const getZHADeviceActions = async ( ); } - if (zhaDevice.device_type !== "Coordinator") { - actions.push( - ...[ - { - label: hass.localize( - "ui.dialogs.zha_device_info.buttons.zigbee_information" + actions.push( + ...[ + { + label: hass.localize( + "ui.dialogs.zha_device_info.buttons.zigbee_information" + ), + action: () => showZHADeviceZigbeeInfoDialog(el, { device: zhaDevice }), + }, + { + label: hass.localize("ui.dialogs.zha_device_info.buttons.clusters"), + action: () => showZHAClusterDialog(el, { device: zhaDevice }), + }, + { + label: hass.localize( + "ui.dialogs.zha_device_info.buttons.view_in_visualization" + ), + action: () => + navigate(`/config/zha/visualization/${zhaDevice!.device_reg_id}`), + }, + ] + ); + + if (!zhaDevice.active_coordinator) { + actions.push({ + label: hass.localize("ui.dialogs.zha_device_info.buttons.remove"), + classes: "warning", + action: async () => { + const confirmed = await showConfirmationDialog(el, { + text: hass.localize( + "ui.dialogs.zha_device_info.confirmations.remove" ), - action: () => - showZHADeviceZigbeeInfoDialog(el, { device: zhaDevice }), - }, - { - label: hass.localize("ui.dialogs.zha_device_info.buttons.clusters"), - action: () => showZHAClusterDialog(el, { device: zhaDevice }), - }, - { - label: hass.localize( - "ui.dialogs.zha_device_info.buttons.view_in_visualization" - ), - action: () => - navigate(`/config/zha/visualization/${zhaDevice!.device_reg_id}`), - }, - { - label: hass.localize("ui.dialogs.zha_device_info.buttons.remove"), - classes: "warning", - action: async () => { - const confirmed = await showConfirmationDialog(el, { - text: hass.localize( - "ui.dialogs.zha_device_info.confirmations.remove" - ), - }); + }); - if (!confirmed) { - return; - } + if (!confirmed) { + return; + } - await hass.callService("zha", "remove", { - ieee: zhaDevice.ieee, - }); + await hass.callService("zha", "remove", { + ieee: zhaDevice.ieee, + }); - history.back(); - }, - }, - ] - ); + history.back(); + }, + }); } return actions;