Skip to content

Commit 74f2986

Browse files
authored
fix: fix api proxy cert blocking the event loop (#1030)
1 parent ac9eb97 commit 74f2986

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

custom_components/tesla_custom/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,17 @@ async def async_setup_entry(hass, config_entry):
142142
# Because users can have multiple accounts, we always
143143
# create a new session so they have separate cookies
144144

145-
if config.get(CONF_API_PROXY_CERT):
145+
if api_proxy_cert := config.get(CONF_API_PROXY_CERT):
146146
try:
147-
SSL_CONTEXT.load_verify_locations(config[CONF_API_PROXY_CERT])
148-
_LOGGER.debug("Trusting CA: %s", SSL_CONTEXT.get_ca_certs()[-1])
147+
await hass.async_add_executor_job(
148+
SSL_CONTEXT.load_verify_locations, api_proxy_cert
149+
)
150+
if _LOGGER.isEnabledFor(logging.DEBUG):
151+
_LOGGER.debug("Trusting CA: %s", SSL_CONTEXT.get_ca_certs()[-1])
149152
except (FileNotFoundError, ssl.SSLError):
150153
_LOGGER.warning(
151154
"Unable to load custom SSL certificate from %s",
152-
config[CONF_API_PROXY_CERT],
155+
api_proxy_cert,
153156
)
154157

155158
async_client = httpx.AsyncClient(
@@ -181,7 +184,6 @@ async def async_setup_entry(hass, config_entry):
181184
polling_policy=config_entry.options.get(
182185
CONF_POLLING_POLICY, DEFAULT_POLLING_POLICY
183186
),
184-
api_proxy_cert=config.get(CONF_API_PROXY_CERT),
185187
api_proxy_url=config.get(CONF_API_PROXY_URL),
186188
client_id=config.get(CONF_CLIENT_ID),
187189
)

0 commit comments

Comments
 (0)