Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix disk i/o blocking calls #1465

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions custom_components/sonoff/core/xutils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from homeassistant.core import HomeAssistant


def source_hash() -> str:
async def source_hash() -> str:
if source_hash.__doc__:
return source_hash.__doc__

Expand All @@ -11,13 +11,13 @@ def source_hash() -> str:

m = hashlib.md5()
path = os.path.dirname(os.path.dirname(__file__))
for root, dirs, files in os.walk(path):
for root, dirs, files in await HomeAssistant.async_add_executor_job(os.walk, path):
dirs.sort()
for file in sorted(files):
if not file.endswith(".py"):
continue
path = os.path.join(root, file)
with open(path, "rb") as f:
with await HomeAssistant.async_add_executor_job(open, path, "rb") as f:
m.update(f.read())

source_hash.__doc__ = m.hexdigest()[:7]
Expand Down
4 changes: 2 additions & 2 deletions custom_components/sonoff/system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def system_health_info(hass: HomeAssistant):

integration = hass.data["integrations"][DOMAIN]
info = {
"version": f"{integration.version} ({xutils.source_hash()})",
"version": f"{integration.version} ({await xutils.source_hash()})",
"cloud_online": f"{cloud_online} / {cloud_total}",
"local_online": f"{local_online} / {local_total}",
}
Expand All @@ -59,7 +59,7 @@ async def setup_debug(hass: HomeAssistant, logger: Logger):

integration = hass.data["integrations"][DOMAIN]
info = await hass.helpers.system_info.async_get_system_info()
info[DOMAIN + "_version"] = f"{integration.version} ({xutils.source_hash()})"
info[DOMAIN + "_version"] = f"{integration.version} ({await xutils.source_hash()})"
logger.debug(f"SysInfo: {info}")

integration.manifest["issue_tracker"] = view.url
Expand Down
Loading