mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Fix blocking I/O in xmpp notify to read uploaded files (#120801)
detected by ruff in https://github.com/home-assistant/core/pull/120799
This commit is contained in:
parent
0dcfd38cdc
commit
0ec07001bd
@ -305,16 +305,20 @@ async def async_send_message( # noqa: C901
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
async def upload_file_from_path(self, path, timeout=None):
|
||||
def _read_upload_file(self, path: str) -> bytes:
|
||||
"""Read file from path."""
|
||||
with open(path, "rb") as upfile:
|
||||
_LOGGER.debug("Reading file %s", path)
|
||||
return upfile.read()
|
||||
|
||||
async def upload_file_from_path(self, path: str, timeout=None):
|
||||
"""Upload a file from a local file path via XEP_0363."""
|
||||
_LOGGER.info("Uploading file from path, %s", path)
|
||||
|
||||
if not hass.config.is_allowed_path(path):
|
||||
raise PermissionError("Could not access file. Path not allowed")
|
||||
|
||||
with open(path, "rb") as upfile:
|
||||
_LOGGER.debug("Reading file %s", path)
|
||||
input_file = upfile.read()
|
||||
input_file = await hass.async_add_executor_job(self._read_upload_file, path)
|
||||
filesize = len(input_file)
|
||||
_LOGGER.debug("Filesize is %s bytes", filesize)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user