diff --git a/homeassistant/core.py b/homeassistant/core.py index 72e33a1d786..6c2d7711a0d 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -434,12 +434,13 @@ class HomeAssistant: self.import_executor = InterruptibleThreadPoolExecutor( max_workers=1, thread_name_prefix="ImportExecutor" ) + self._loop_thread_id = getattr( + self.loop, "_thread_ident", getattr(self.loop, "_thread_id") + ) def verify_event_loop_thread(self, what: str) -> None: """Report and raise if we are not running in the event loop thread.""" - if ( - loop_thread_ident := self.loop.__dict__.get("_thread_ident") - ) and loop_thread_ident != threading.get_ident(): + if self._loop_thread_id != threading.get_ident(): from .helpers import frame # pylint: disable=import-outside-toplevel # frame is a circular import, so we import it here diff --git a/tests/common.py b/tests/common.py index 252e5309411..6e7cf1b21f3 100644 --- a/tests/common.py +++ b/tests/common.py @@ -174,6 +174,7 @@ def get_test_home_assistant() -> Generator[HomeAssistant, None, None]: """Run event loop.""" loop._thread_ident = threading.get_ident() + hass._loop_thread_id = loop._thread_ident loop.run_forever() loop_stop_event.set()