Ensure konnected unsubscribes during entry unloads (#34291)

This commit is contained in:
Kit Klein 2020-04-16 17:08:50 -04:00 committed by GitHub
parent 0d60d40512
commit ab352c3bc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -58,6 +58,7 @@ from .const import (
PIN_TO_ZONE,
STATE_HIGH,
STATE_LOW,
UNDO_UPDATE_LISTENER,
UPDATE_ENDPOINT,
ZONE_TO_PIN,
ZONES,
@ -254,7 +255,7 @@ async def async_setup(hass: HomeAssistant, config: dict):
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up panel from a config entry."""
client = AlarmPanel(hass, entry)
# create a data store in hass.data[DOMAIN][CONF_DEVICES]
# creates a panel data store in hass.data[DOMAIN][CONF_DEVICES]
await client.async_save_data()
try:
@ -267,7 +268,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
)
entry.add_update_listener(async_entry_updated)
# config entry specific data to enable unload
hass.data[DOMAIN][entry.entry_id] = {
UNDO_UPDATE_LISTENER: entry.add_update_listener(async_entry_updated)
}
return True
@ -281,8 +286,12 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
]
)
)
hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()
if unload_ok:
hass.data[DOMAIN][CONF_DEVICES].pop(entry.data[CONF_ID])
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok

View File

@ -47,3 +47,5 @@ ZONE_TO_PIN = {zone: pin for pin, zone in PIN_TO_ZONE.items()}
ENDPOINT_ROOT = "/api/konnected"
UPDATE_ENDPOINT = ENDPOINT_ROOT + r"/device/{device_id:[a-zA-Z0-9]+}"
SIGNAL_DS18B20_NEW = "konnected.ds18b20.new"
UNDO_UPDATE_LISTENER = "undo_update_listener"