diff --git a/homeassistant/components/deconz/deconz_device.py b/homeassistant/components/deconz/deconz_device.py index 4bcd63c8fa2..ab4d4083095 100644 --- a/homeassistant/components/deconz/deconz_device.py +++ b/homeassistant/components/deconz/deconz_device.py @@ -81,8 +81,7 @@ 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) - if self.entity_id in self.gateway.deconz_ids: - del self.gateway.deconz_ids[self.entity_id] + del self.gateway.deconz_ids[self.entity_id] self.gateway.entities[self.TYPE].remove(self.unique_id) @callback diff --git a/homeassistant/components/deconz/gateway.py b/homeassistant/components/deconz/gateway.py index 5ec07c40754..2a853d097f3 100644 --- a/homeassistant/components/deconz/gateway.py +++ b/homeassistant/components/deconz/gateway.py @@ -34,7 +34,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].get(config_entry.unique_id) + return hass.data[DOMAIN][config_entry.unique_id] class DeconzGateway: @@ -192,9 +192,6 @@ class DeconzGateway: """ gateway = get_gateway_from_config_entry(hass, entry) - if not gateway: - return - if gateway.api.host != gateway.host: gateway.api.close() gateway.api.host = gateway.host diff --git a/tests/components/deconz/test_gateway.py b/tests/components/deconz/test_gateway.py index c54267c1d03..2ac14c136a7 100644 --- a/tests/components/deconz/test_gateway.py +++ b/tests/components/deconz/test_gateway.py @@ -113,9 +113,8 @@ async def test_gateway_setup_fails(hass): with patch( "homeassistant.components.deconz.gateway.get_gateway", side_effect=Exception ): - config_entry = await setup_deconz_integration(hass) - gateway = get_gateway_from_config_entry(hass, config_entry) - assert gateway is None + await setup_deconz_integration(hass) + assert not hass.data[deconz.DOMAIN] async def test_connection_status_signalling(hass):