From 8017bc6776c6826c0a3b485f167c38906c33a5fb Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 3 Jul 2024 12:37:29 -0700 Subject: [PATCH] Fix blocking I/O in demo mailbox (#121097) --- homeassistant/components/demo/mailbox.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/demo/mailbox.py b/homeassistant/components/demo/mailbox.py index 3ec80e47118..e0cdd05782d 100644 --- a/homeassistant/components/demo/mailbox.py +++ b/homeassistant/components/demo/mailbox.py @@ -66,14 +66,17 @@ class DemoMailbox(Mailbox): """Return if messages have attached media files.""" return True + def _get_media(self) -> bytes: + """Return the media blob for the msgid.""" + audio_path = os.path.join(os.path.dirname(__file__), "tts.mp3") + with open(audio_path, "rb") as file: + return file.read() + async def async_get_media(self, msgid: str) -> bytes: """Return the media blob for the msgid.""" if msgid not in self._messages: raise StreamError("Message not found") - - audio_path = os.path.join(os.path.dirname(__file__), "tts.mp3") - with open(audio_path, "rb") as file: - return file.read() + return await self.hass.async_add_executor_job(self._get_media) async def async_get_messages(self) -> list[dict[str, Any]]: """Return a list of the current messages."""