Skip to content

Commit

Permalink
Fix blocking call to listdir inside the event loop #730
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Sep 8, 2024
1 parent d723584 commit 61f3ea9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/webrtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
return True

# 3. Serve go2rtc binary manually
binary = await utils.validate_binary(hass)
binary = await hass.async_add_executor_job(utils.validate_binary, hass)
if not binary:
return False

Expand Down
7 changes: 4 additions & 3 deletions custom_components/webrtc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from urllib.parse import urljoin

import jwt
import requests
from aiohttp import web
from homeassistant.components.frontend import add_extra_js_url
from homeassistant.components.http.auth import DATA_SIGN_SECRET, SIGN_QUERY_PARAM
Expand Down Expand Up @@ -62,7 +63,7 @@ def unzip(content: bytes) -> bytes:
return f.read()


async def validate_binary(hass: HomeAssistant) -> Optional[str]:
def validate_binary(hass: HomeAssistant) -> Optional[str]:
filename = f"go2rtc-{BINARY_VERSION}"
if platform.system() == "Windows":
filename += ".exe"
Expand All @@ -83,11 +84,11 @@ async def validate_binary(hass: HomeAssistant) -> Optional[str]:
f"v{BINARY_VERSION}/{get_arch()}"
)
_LOGGER.debug(f"Download new binary: {url}")
r = await async_get_clientsession(hass).get(url)
r = requests.get(url)
if not r.ok:
return None

raw = await r.read()
raw = r.content

# unzip binary for windows
if url.endswith(".zip"):
Expand Down

0 comments on commit 61f3ea9

Please sign in to comment.