diff --git a/supervisor/coresys.py b/supervisor/coresys.py index 2e3fcbe78..46abeec3a 100644 --- a/supervisor/coresys.py +++ b/supervisor/coresys.py @@ -68,7 +68,7 @@ class CoreSys: # External objects self._loop: asyncio.BaseEventLoop = asyncio.get_running_loop() - self._websession = None + self._websession: aiohttp.ClientSession = aiohttp.ClientSession() # Global objects self._config: CoreConfig = CoreConfig() @@ -101,8 +101,10 @@ class CoreSys: self._bus: Bus | None = None self._mounts: MountManager | None = None - # Setup aiohttp session - self.create_websession() + # Set default header for aiohttp + self._websession._default_headers = MappingProxyType( + {aiohttp.hdrs.USER_AGENT: SERVER_SOFTWARE} + ) # Task factory attributes self._set_task_context: list[Callable[[Context], Context]] = [] @@ -582,16 +584,6 @@ class CoreSys: return self.loop.run_in_executor(None, funct, *args) - def create_websession(self) -> None: - """Create a new aiohttp session.""" - if self._websession: - self.create_task(self._websession.close()) - - # Create session and set default header for aiohttp - self._websession: aiohttp.ClientSession = aiohttp.ClientSession( - headers=MappingProxyType({aiohttp.hdrs.USER_AGENT: SERVER_SOFTWARE}) - ) - def _create_context(self) -> Context: """Create a new context for a task.""" context = copy_context() diff --git a/supervisor/supervisor.py b/supervisor/supervisor.py index 9ddc7829c..99b85d4e9 100644 --- a/supervisor/supervisor.py +++ b/supervisor/supervisor.py @@ -292,8 +292,6 @@ class Supervisor(CoreSysAttributes): "https://checkonline.home-assistant.io/online.txt", timeout=timeout ) except (ClientError, TimeoutError): - # Need to recreate the websession to avoid stale connection checks - self.coresys.create_websession() self.connectivity = False else: self.connectivity = True