From d110d4291300f5100b8e245c9634a87dee22a9e6 Mon Sep 17 00:00:00 2001 From: Greg Dowling Date: Tue, 26 Jan 2021 07:15:07 +0000 Subject: [PATCH] Fix Vera race condition on start (#45535) --- homeassistant/components/vera/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/vera/__init__.py b/homeassistant/components/vera/__init__.py index fdc8503ed70..3fd1c189b63 100644 --- a/homeassistant/components/vera/__init__.py +++ b/homeassistant/components/vera/__init__.py @@ -110,9 +110,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b # Initialize the Vera controller. subscription_registry = SubscriptionRegistry(hass) controller = veraApi.VeraController(base_url, subscription_registry) - await hass.async_add_executor_job(controller.start) - - hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, controller.stop) try: all_devices = await hass.async_add_executor_job(controller.get_devices) @@ -151,6 +148,13 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b hass.config_entries.async_forward_entry_setup(config_entry, platform) ) + def stop_subscription(event): + """Stop SubscriptionRegistry updates.""" + controller.stop() + + await hass.async_add_executor_job(controller.start) + hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription) + return True