Skip to content

Commit

Permalink
Fix: Address blocking file operation in log (jcwillox#145)
Browse files Browse the repository at this point in the history
- Resolved Home Assistant warning about blocking file operations in the `auto_backup` integration (jcwillox#145).
- Updated `handlers.py` to replace synchronous `open` calls with `aiofiles.open` for non-blocking file writes.
- Improved compatibility with Home Assistant's asyncio architecture, preventing event loop warnings.
- Verified changes to ensure integration functionality remains intact.
  • Loading branch information
Doorshifter committed Dec 8, 2024
1 parent 413dfe6 commit d4330e1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added custom_components/.DS_Store
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

0 comments on commit d4330e1

Please sign in to comment.