Fix telegram doing blocking I/O in the event loop (#118531)
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(
|
||||
hass,
|
||||
url=None,
|
||||
|
@ -342,7 +348,9 @@ async def load_data(
|
|||
)
|
||||
elif filepath is not None:
|
||||
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)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue