diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index 7a056665ed4..df5bebb47d4 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -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: