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
04ab74589a
commit
d4ecbc91c3
1 changed files with 8 additions and 4 deletions
|
@ -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…
Add table
Reference in a new issue