From 8c4b5719018b16e6b6c3d5fa2c752ffb5f9b8910 Mon Sep 17 00:00:00 2001
From: jjlawren <jjlawren@users.noreply.github.com>
Date: Thu, 1 Oct 2020 14:56:15 -0500
Subject: [PATCH] Plex websocket callback async cleanup (#40992)

---
 homeassistant/components/plex/__init__.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/homeassistant/components/plex/__init__.py b/homeassistant/components/plex/__init__.py
index 3682f362700..f0052ef8830 100644
--- a/homeassistant/components/plex/__init__.py
+++ b/homeassistant/components/plex/__init__.py
@@ -29,6 +29,7 @@ from homeassistant.const import (
     CONF_VERIFY_SSL,
     EVENT_HOMEASSISTANT_STOP,
 )
+from homeassistant.core import callback
 from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
 from homeassistant.helpers import config_validation as cv
 from homeassistant.helpers.aiohttp_client import async_get_clientsession
@@ -150,6 +151,7 @@ async def async_setup_entry(hass, entry):
     hass.data[PLEX_DOMAIN][DISPATCHERS].setdefault(server_id, [])
     hass.data[PLEX_DOMAIN][DISPATCHERS][server_id].append(unsub)
 
+    @callback
     def plex_websocket_callback(signal, data, error):
         """Handle callbacks from plexwebsocket library."""
         if signal == SIGNAL_CONNECTION_STATE:
@@ -167,9 +169,7 @@ async def async_setup_entry(hass, entry):
                     entry.data[CONF_SERVER],
                     error,
                 )
-                asyncio.run_coroutine_threadsafe(
-                    hass.config_entries.async_reload(entry.entry_id), hass.loop
-                )
+                hass.async_create_task(hass.config_entries.async_reload(entry.entry_id))
 
         elif signal == SIGNAL_DATA:
             async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
-- 
GitLab