mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 01:07:10 +00:00
Fix blocking I/O in demo mailbox (#121097)
This commit is contained in:
parent
2040c285b1
commit
8017bc6776
@ -66,14 +66,17 @@ class DemoMailbox(Mailbox):
|
|||||||
"""Return if messages have attached media files."""
|
"""Return if messages have attached media files."""
|
||||||
return True
|
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:
|
async def async_get_media(self, msgid: str) -> bytes:
|
||||||
"""Return the media blob for the msgid."""
|
"""Return the media blob for the msgid."""
|
||||||
if msgid not in self._messages:
|
if msgid not in self._messages:
|
||||||
raise StreamError("Message not found")
|
raise StreamError("Message not found")
|
||||||
|
return await self.hass.async_add_executor_job(self._get_media)
|
||||||
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_messages(self) -> list[dict[str, Any]]:
|
async def async_get_messages(self) -> list[dict[str, Any]]:
|
||||||
"""Return a list of the current messages."""
|
"""Return a list of the current messages."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user