mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Fix telegram doing blocking I/O in the event loop (#118531)
This commit is contained in:
parent
76391d71d6
commit
5ed9d58a7b
@ -284,6 +284,12 @@ SERVICE_MAP = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _read_file_as_bytesio(file_path: str) -> io.BytesIO:
|
||||||
|
"""Read a file and return it as a BytesIO object."""
|
||||||
|
with open(file_path, "rb") as file:
|
||||||
|
return io.BytesIO(file.read())
|
||||||
|
|
||||||
|
|
||||||
async def load_data(
|
async def load_data(
|
||||||
hass,
|
hass,
|
||||||
url=None,
|
url=None,
|
||||||
@ -342,7 +348,9 @@ async def load_data(
|
|||||||
)
|
)
|
||||||
elif filepath is not None:
|
elif filepath is not None:
|
||||||
if hass.config.is_allowed_path(filepath):
|
if hass.config.is_allowed_path(filepath):
|
||||||
return open(filepath, "rb")
|
return await hass.async_add_executor_job(
|
||||||
|
_read_file_as_bytesio, filepath
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER.warning("'%s' are not secure to load data from!", filepath)
|
_LOGGER.warning("'%s' are not secure to load data from!", filepath)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user