WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit ec4542e

Browse files
committed
fix: create ssl context safely
1 parent c06a441 commit ec4542e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

python_snoo/snoo.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import logging
44
import secrets
5+
import ssl
56
import uuid
67
from datetime import datetime as dt
78
from typing import Callable
@@ -292,6 +293,10 @@ async def subscribe_mqtt(self, device: SnooDevice, function: Callable):
292293

293294
logging.debug(f"Attempting to connect to wss://{host}:{port}{websocket_path}")
294295

296+
# The default SSL context creation is a blocking I/O operation.
297+
# Run it in a separate thread to avoid blocking the Home Assistant event loop.
298+
ssl_context = await asyncio.to_thread(ssl.create_default_context)
299+
295300
try:
296301
async with aiomqtt.Client(
297302
hostname=host,
@@ -302,7 +307,7 @@ async def subscribe_mqtt(self, device: SnooDevice, function: Callable):
302307
transport="websockets",
303308
websocket_path=websocket_path,
304309
websocket_headers=headers,
305-
tls_params=aiomqtt.TLSParameters(),
310+
tls_context=ssl_context,
306311
protocol=aiomqtt.ProtocolVersion.V31,
307312
timeout=10,
308313
) as client:

0 commit comments

Comments
 (0)