diff --git a/homeassistant/components/deconz/deconz_device.py b/homeassistant/components/deconz/deconz_device.py index b3dedf6cf00..0724f9f9b45 100644 --- a/homeassistant/components/deconz/deconz_device.py +++ b/homeassistant/components/deconz/deconz_device.py @@ -86,9 +86,10 @@ class DeconzDevice(DeconzBase, Entity): async def async_will_remove_from_hass(self) -> None: """Disconnect device object when removed.""" self._device.remove_callback(self.async_update_callback) - del self.gateway.deconz_ids[self.entity_id] - for unsub_dispatcher in self.listeners: - unsub_dispatcher() + if self.entity_id in self.gateway.deconz_ids: + del self.gateway.deconz_ids[self.entity_id] + for unsub_dispatcher in self.listeners: + unsub_dispatcher() async def async_remove_self(self, deconz_ids: list) -> None: """Schedule removal of this entity. diff --git a/homeassistant/components/deconz/gateway.py b/homeassistant/components/deconz/gateway.py index b59c80a0dc8..eb83f5c15c5 100644 --- a/homeassistant/components/deconz/gateway.py +++ b/homeassistant/components/deconz/gateway.py @@ -31,7 +31,7 @@ from .errors import AuthenticationRequired, CannotConnect @callback def get_gateway_from_config_entry(hass, config_entry): """Return gateway with a matching bridge id.""" - return hass.data[DOMAIN][config_entry.unique_id] + return hass.data[DOMAIN].get(config_entry.unique_id) class DeconzGateway: @@ -126,6 +126,8 @@ class DeconzGateway: Causes for this is either discovery updating host address or config entry options changing. """ gateway = get_gateway_from_config_entry(hass, entry) + if not gateway: + return if gateway.api.host != entry.data[CONF_HOST]: gateway.api.close() gateway.api.host = entry.data[CONF_HOST] diff --git a/tests/ignore_uncaught_exceptions.py b/tests/ignore_uncaught_exceptions.py index 1a37f2d0f54..26170ac2b86 100644 --- a/tests/ignore_uncaught_exceptions.py +++ b/tests/ignore_uncaught_exceptions.py @@ -6,11 +6,6 @@ IGNORE_UNCAUGHT_EXCEPTIONS = [ ("tests.components.cast.test_media_player", "test_entry_setup_platform_not_ready"), ("tests.components.config.test_automation", "test_delete_automation"), ("tests.components.config.test_group", "test_update_device_config"), - ("tests.components.deconz.test_binary_sensor", "test_allow_clip_sensor"), - ("tests.components.deconz.test_climate", "test_clip_climate_device"), - ("tests.components.deconz.test_init", "test_unload_entry_multiple_gateways"), - ("tests.components.deconz.test_light", "test_disable_light_groups"), - ("tests.components.deconz.test_sensor", "test_allow_clip_sensors"), ("tests.components.default_config.test_init", "test_setup"), ("tests.components.demo.test_init", "test_setting_up_demo"), ("tests.components.discovery.test_init", "test_discover_config_flow"),