From b657a7d68b76909da336a4cfba1a0d5f6cfab0d6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 29 Apr 2022 13:18:06 -0500 Subject: [PATCH] Fix unsafe websocket stop call in isy994 (#71071) Fixes ``` 2022-04-29 12:49:10 ERROR (MainThread) [homeassistant.config_entries] Error unloading entry Alexander (192.168.209.83) for isy994 Traceback (most recent call last): File "/Users/bdraco/home-assistant/homeassistant/config_entries.py", line 474, in async_unload result = await component.async_unload_entry(hass, self) File "/Users/bdraco/home-assistant/homeassistant/components/isy994/__init__.py", line 294, in async_unload_entry await hass.async_add_executor_job(_stop_auto_update) File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/Users/bdraco/home-assistant/homeassistant/components/isy994/__init__.py", line 292, in _stop_auto_update isy.websocket.stop() File "/Users/bdraco/home-assistant/venv/lib/python3.9/site-packages/pyisy/events/websocket.py", line 110, in stop self.websocket_task.cancel() File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 753, in call_soon self._check_thread() File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 790, in _check_thread raise RuntimeError( RuntimeError: Non-thread-safe operation invoked on an event loop other than the current one ``` --- homeassistant/components/isy994/__init__.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/isy994/__init__.py b/homeassistant/components/isy994/__init__.py index ba152c5d840..ae48fc18b5b 100644 --- a/homeassistant/components/isy994/__init__.py +++ b/homeassistant/components/isy994/__init__.py @@ -288,14 +288,10 @@ async def async_unload_entry( hass_isy_data = hass.data[DOMAIN][entry.entry_id] - isy = hass_isy_data[ISY994_ISY] + isy: ISY = hass_isy_data[ISY994_ISY] - def _stop_auto_update() -> None: - """Stop the isy auto update.""" - _LOGGER.debug("ISY Stopping Event Stream and automatic updates") - isy.websocket.stop() - - await hass.async_add_executor_job(_stop_auto_update) + _LOGGER.debug("ISY Stopping Event Stream and automatic updates") + isy.websocket.stop() if unload_ok: hass.data[DOMAIN].pop(entry.entry_id)