From d4330e18b7316fc68dd28ff38194f98e583c3cdc Mon Sep 17 00:00:00 2001 From: Doorshifter Date: Sun, 8 Dec 2024 14:38:57 +0100 Subject: [PATCH] Fix: Address blocking file operation in log (#145) - Resolved Home Assistant warning about blocking file operations in the `auto_backup` integration (#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. --- .DS_Store | Bin 0 -> 6148 bytes custom_components/.DS_Store | Bin 0 -> 6148 bytes custom_components/auto_backup/handlers.py | 7 ++++--- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 .DS_Store create mode 100644 custom_components/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..153f549af5752777589bd9a394d9f36d23853d89 GIT binary patch literal 6148 zcmeHKyG{c!5S)b+k!V6k>0jUvPEq&*J|GbZUEq)|>95Ln@oCIHn$tlQ(L}S-dhGR% zEl+WK3&7Ur!!xh~u%tWU;=|m0-+g9x6)_^6XY}~M7W=?i`mX`!K9X_9fYXHk#nmU? z=_d?_VSjw<`=h7Jq<|EV0#ZN(CCg`;g}eo4i3=* z5El%GaUQ({v3Y>l6^@CF&@8FMq*}EYmUPBj<#mN)V$xyNd|2IV)uCA2&huNO!@5L` zQa}n!6}Zpk%Ip6N{g3{CO43RSNP(MDz!sa=&6-cD+B$oj*V;zk(LLvz?#6jgI7B%n jMmgrf%kfhrWnS|+_q)O|G3bm3ov5Dy*F`1;{#$_`CL0*6 literal 0 HcmV?d00001 diff --git a/custom_components/.DS_Store b/custom_components/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..535d64704bc650bc28466210635761043721a41b GIT binary patch literal 6148 zcmeHKyG{c!5S)b+kq6{wlsJpT_K?IURJNiDsqs*y|lz zp5pcvfbGW9Bd`UqraR)>ho$+x`@-%jVnjO6c)`>g+CT4id{Wic#pArzHu@{wb1rl@&V#}s$}us@F&AEr eA0jF9n$Nl43#Y`OGahuJeg<3@nH2bM1%3eE02SW= literal 0 HcmV?d00001 diff --git a/custom_components/auto_backup/handlers.py b/custom_components/auto_backup/handlers.py index 456c16f..d67b066 100644 --- a/custom_components/auto_backup/handlers.py +++ b/custom_components/auto_backup/handlers.py @@ -1,3 +1,4 @@ +import aiofiles import asyncio import logging import shutil @@ -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