Fix the radio browser doing I/O in the event loop (#118842)

This commit is contained in:
Paulus Schoutsen 2024-06-04 23:59:25 -04:00 committed by GitHub
parent 678c06beb3
commit 72309364f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,7 @@ from __future__ import annotations
import mimetypes
from radios import FilterBy, Order, RadioBrowser, Station
from radios.radio_browser import pycountry
from homeassistant.components.media_player import MediaClass, MediaType
from homeassistant.components.media_source.error import Unresolvable
@ -145,6 +146,8 @@ class RadioMediaSource(MediaSource):
# We show country in the root additionally, when there is no item
if not item.identifier or category == "country":
# Trigger the lazy loading of the country database to happen inside the executor
await self.hass.async_add_executor_job(lambda: len(pycountry.countries))
countries = await radios.countries(order=Order.NAME)
return [
BrowseMediaSource(