From 01fcc41aa067bce649721fa1d04c800b6576eb02 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Sat, 20 Mar 2021 17:26:23 -0400 Subject: [PATCH] only block coord removal if it is active (#48147) --- homeassistant/components/zha/api.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/zha/api.py b/homeassistant/components/zha/api.py index 45f7d540052..c8839acf856 100644 --- a/homeassistant/components/zha/api.py +++ b/homeassistant/components/zha/api.py @@ -60,6 +60,7 @@ from .core.helpers import ( get_matched_clusters, qr_to_install_code, ) +from .core.typing import ZhaDeviceType, ZhaGatewayType _LOGGER = logging.getLogger(__name__) @@ -892,9 +893,12 @@ def async_load_api(hass): async def remove(service): """Remove a node from the network.""" ieee = service.data[ATTR_IEEE] - zha_gateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY] - zha_device = zha_gateway.get_device(ieee) - if zha_device is not None and zha_device.is_coordinator: + zha_gateway: ZhaGatewayType = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY] + zha_device: ZhaDeviceType = zha_gateway.get_device(ieee) + if zha_device is not None and ( + zha_device.is_coordinator + and zha_device.ieee == zha_gateway.application_controller.ieee + ): _LOGGER.info("Removing the coordinator (%s) is not allowed", ieee) return _LOGGER.info("Removing node %s", ieee)