mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Register on HA stop event to gracefully shutdown HomematicIP Cloud connections (#31289)
* Register on HA stop event to gracefully shutdown HomematicIP Cloud connections * fixes after review * Fix lint * switch to unload_entry * Save listener * Switch back to hap.async_reset()
This commit is contained in:
parent
73ea34e417
commit
cd1aa46404
@ -11,7 +11,7 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_NAME
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_NAME, EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.config_validation import comp_entity_ids
|
||||
@ -348,6 +348,16 @@ 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()
|
||||
)
|
||||
|
||||
# Register hap as device in registry.
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
home = hap.home
|
||||
@ -367,4 +377,5 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
hap = hass.data[DOMAIN].pop(entry.unique_id)
|
||||
hap.reset_connection_listener()
|
||||
return await hap.async_reset()
|
||||
|
@ -81,6 +81,7 @@ class HomematicipHAP:
|
||||
self._tries = 0
|
||||
self._accesspoint_connected = True
|
||||
self.hmip_device_by_entity_id = {}
|
||||
self.reset_connection_listener = None
|
||||
|
||||
async def async_setup(self, tries: int = 0) -> bool:
|
||||
"""Initialize connection."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user