/
/
/
1"""Configuration entries for the AI Radio plugin."""
2
3from __future__ import annotations
4
5import asyncio
6from typing import TYPE_CHECKING
7
8from music_assistant_models.config_entries import ConfigEntry, ConfigValueOption, ConfigValueType
9from music_assistant_models.enums import ConfigEntryType
10
11from music_assistant.helpers.countries import get_country_codes
12from music_assistant.helpers.datetime import host_timezone_name
13
14from .constants import (
15 CONF_TIMEZONE,
16 CONF_WEATHER_CITY,
17 CONF_WEATHER_COUNTRY,
18)
19
20if TYPE_CHECKING:
21 from music_assistant.mass import MusicAssistant
22
23
24async def get_config_entries(
25 mass: MusicAssistant,
26 instance_id: str | None = None, # noqa: ARG001
27 action: str | None = None, # noqa: ARG001
28 values: dict[str, ConfigValueType] | None = None, # noqa: ARG001
29) -> tuple[ConfigEntry, ...]:
30 """Return Config entries to setup this provider."""
31 country_codes = await asyncio.to_thread(get_country_codes)
32 country_options = [
33 ConfigValueOption(title=name, value=code) for code, name in country_codes.items()
34 ]
35 # default the weather country to the region of the server's language, mirroring
36 # the itunes_podcasts locale precedent
37 region = mass.metadata.locale.split("_")[-1].upper()
38 return (
39 ConfigEntry(
40 key=CONF_TIMEZONE,
41 type=ConfigEntryType.STRING,
42 default_value=host_timezone_name(),
43 advanced=True,
44 ),
45 ConfigEntry(
46 key=CONF_WEATHER_CITY,
47 type=ConfigEntryType.STRING,
48 default_value="",
49 ),
50 ConfigEntry(
51 key=CONF_WEATHER_COUNTRY,
52 type=ConfigEntryType.STRING,
53 options=country_options,
54 default_value=region if region in country_codes else "",
55 ),
56 )
57