From fe4e6f24f547f398a03b4ce60670a4c63aae6403 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 6 Aug 2024 08:32:58 -0500 Subject: [PATCH] Fix sense doing blocking I/O in the event loop (#123247) --- homeassistant/components/sense/__init__.py | 12 ++++++++++-- homeassistant/components/sense/config_flow.py | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/sense/__init__.py b/homeassistant/components/sense/__init__.py index 28408c0cb7d..58e993ad6e0 100644 --- a/homeassistant/components/sense/__init__.py +++ b/homeassistant/components/sense/__init__.py @@ -2,6 +2,7 @@ from dataclasses import dataclass from datetime import timedelta +from functools import partial import logging from typing import Any @@ -80,8 +81,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: SenseConfigEntry) -> boo client_session = async_get_clientsession(hass) - gateway = ASyncSenseable( - api_timeout=timeout, wss_timeout=timeout, client_session=client_session + # Creating the AsyncSenseable object loads + # ssl certificates which does blocking IO + gateway = await hass.async_add_executor_job( + partial( + ASyncSenseable, + api_timeout=timeout, + wss_timeout=timeout, + client_session=client_session, + ) ) gateway.rate_limit = ACTIVE_UPDATE_RATE diff --git a/homeassistant/components/sense/config_flow.py b/homeassistant/components/sense/config_flow.py index 25c6898aec8..dab80b99e1a 100644 --- a/homeassistant/components/sense/config_flow.py +++ b/homeassistant/components/sense/config_flow.py @@ -1,6 +1,7 @@ """Config flow for Sense integration.""" from collections.abc import Mapping +from functools import partial import logging from typing import Any @@ -48,8 +49,15 @@ class SenseConfigFlow(ConfigFlow, domain=DOMAIN): timeout = self._auth_data[CONF_TIMEOUT] client_session = async_get_clientsession(self.hass) - self._gateway = ASyncSenseable( - api_timeout=timeout, wss_timeout=timeout, client_session=client_session + # Creating the AsyncSenseable object loads + # ssl certificates which does blocking IO + self._gateway = await self.hass.async_add_executor_job( + partial( + ASyncSenseable, + api_timeout=timeout, + wss_timeout=timeout, + client_session=client_session, + ) ) self._gateway.rate_limit = ACTIVE_UPDATE_RATE await self._gateway.authenticate(