diff --git a/homeassistant/components/homematicip_cloud/__init__.py b/homeassistant/components/homematicip_cloud/__init__.py index 63d1f82071b..efc7245de8b 100644 --- a/homeassistant/components/homematicip_cloud/__init__.py +++ b/homeassistant/components/homematicip_cloud/__init__.py @@ -348,14 +348,9 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool if not await hap.async_setup(): return False - async def async_reset_hap_connection(): - """Reset hmip hap connection.""" - await hap.async_reset() - _LOGGER.debug("Reset connection to access point id %s", entry.unique_id) - # Register on HA stop event to gracefully shutdown HomematicIP Cloud connection hap.reset_connection_listener = hass.bus.async_listen_once( - EVENT_HOMEASSISTANT_STOP, async_reset_hap_connection() + EVENT_HOMEASSISTANT_STOP, hap.shutdown ) # Register hap as device in registry. diff --git a/homeassistant/components/homematicip_cloud/hap.py b/homeassistant/components/homematicip_cloud/hap.py index 8a4b7ed5fae..d64d05e72aa 100644 --- a/homeassistant/components/homematicip_cloud/hap.py +++ b/homeassistant/components/homematicip_cloud/hap.py @@ -224,6 +224,17 @@ class HomematicipHAP: self.hmip_device_by_entity_id = {} return True + @callback + def shutdown(self, event) -> None: + """Wrap the call to async_reset. + + Used as an argument to EventBus.async_listen_once. + """ + self.hass.async_create_task(self.async_reset()) + _LOGGER.debug( + "Reset connection to access point id %s", self.config_entry.unique_id + ) + async def get_hap( self, hass: HomeAssistantType, hapid: str, authtoken: str, name: str ) -> AsyncHome: