Skip to content

Commit

Permalink
Remove main thread blocking calls
Browse files Browse the repository at this point in the history
HA is complaining about `open` calls in the main thread which could
cause problem. See https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open
  • Loading branch information
therve committed Dec 9, 2024
1 parent b39c682 commit 9784054
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/freebox_api/aiofreepybox.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ async def _get_freebox_access(

# Read stored application token
logger.info("Read application authorization file")
app_token, track_id, file_app_desc = self._readfile_app_token(token_file)
loop = asyncio.get_running_loop()
app_token, track_id, file_app_desc = await loop.run_in_executor(None, self._readfile_app_token, token_file)

# If no valid token is stored then request a token to freebox api -
# Only for LAN connection
Expand Down Expand Up @@ -237,7 +238,8 @@ async def _get_freebox_access(
logger.info("Application authorization granted")

# Store application token in file
self._writefile_app_token(app_token, track_id, app_desc, token_file)
loop = asyncio.get_running_loop()
await loop.run_in_executor(None, self._writefile_app_token, app_token, track_id, app_desc, token_file)
logger.info("Application token file was generated: %s", token_file)

# Create freebox http access module
Expand Down

0 comments on commit 9784054

Please sign in to comment.