Add missing await to HMIPC (#31415)

* Add missing await to HMIPC

* use callback instead

* Fix call, move callback to hap
This commit is contained in:
SukramJ 2020-02-03 20:27:20 +01:00 committed by GitHub
parent bea7aae8cd
commit 03642d9029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -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.

View File

@ -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: