-
Notifications
You must be signed in to change notification settings - Fork 34
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
Use aiofiles with async open, await data_file #21
Use aiofiles with async open, await data_file #21
Conversation
Signed-off-by: Steve Saunders <[email protected]>
There is more to this. |
This may require an "Await me maybe" logic to support earlier versions of HA. Not sure yet, @BJReplay. |
I would appreciate any information you can provide about this, @autoSteve ! |
Using json.dump() was resulting in cache file zeroed.
On examining the need for "await maybe" I'm pretty sure using async/await always for aiofiles will be good. In all sections of the code that read/write files there are other uses of async. I'll set this as ready for review, @BJReplay. |
Thanks - can you confirm that you have run this code and it is working, and what version of HA it is running against? Can you comment on whether this change is backwards compatible with earlier versions of HA? |
This code is running on my HA. Version 2024.6.1, and just now updated to 2024.6.2 without issue. My thinking is that earlier versions should be okay with it. The solcastapi.py makes use of aiohttp for async REST calls, so switching to aiofiles is very much simpatico. I downgraded to 2023.11.3 as a bit of an extreme case, and all seems well. |
You want I should remove all the surplus space characters everywhere to clean things up before merge, @BJReplay? |
I won't say no! Yes, that would be really appreciated. |
@sh00t2kill and I are happy now. Excess space usage curtailed and committed, @BJReplay. (edit) Forgot to mention that this exact version of solcastapi.py is running on my HA and tests fine. |
The problem with using open is that this is a blocking function.
A solution can be found by utilising the 'aiofiles' library. This pull request changes the blocking open/read data file with an async aiofiles.open, along with an 'await'ed json.load() of the file.
The blocking message has disappeared for this integration for me, which makes complete sense.
Should solve #14.