Fix sense doing blocking I/O in the event loop (#123247)

This commit is contained in:
J. Nick Koston 2024-08-06 08:32:58 -05:00 committed by GitHub
parent f94bf51bb5
commit fe4e6f24f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View File

@ -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

View File

@ -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(