Fix blocking I/O in demo mailbox (#121097)

pull/109196/head^2
J. Nick Koston 2024-07-03 12:37:29 -07:00 committed by GitHub
parent 2040c285b1
commit 8017bc6776
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 4 deletions

View File

@ -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."""