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: warning for blocking event loop when downloading backups #169

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Binary file added .DS_Store
Binary file not shown.
Binary file added custom_components/.DS_Store
jcwillox marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
7 changes: 4 additions & 3 deletions custom_components/auto_backup/handlers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import aiofiles
import asyncio
import logging
import shutil
Expand Down Expand Up @@ -141,13 +142,13 @@ async def download_backup(
if request.status not in (200, 400):
_LOGGER.error("%s return code %d.", command, request.status)
raise HassioAPIError()

with open(destination, "wb") as file:
async with aiofiles.open(destination, "wb") as file:
while True:
chunk = await request.content.read(CHUNK_SIZE)
if not chunk:
break
file.write(chunk)
await file.write(chunk)

_LOGGER.info("Downloaded backup '%s' to '%s'", slug, destination)
return
Expand Down