music-assistant-server

4.5 KBPY
__init__.py
4.5 KB107 lines • python
1"""Base/builtin provider with support for players using slimproto."""
2
3from __future__ import annotations
4
5from typing import TYPE_CHECKING
6
7from music_assistant_models.config_entries import ConfigEntry, ConfigValueType
8from music_assistant_models.enums import ConfigEntryType, ProviderFeature
9
10from music_assistant.constants import CONF_PORT
11
12from .constants import (
13    CONF_CLI_JSON_PORT,
14    CONF_CLI_TELNET_PORT,
15    CONF_DISCOVERY,
16    DEFAULT_SLIMPROTO_PORT,
17)
18from .provider import SqueezelitePlayerProvider
19
20if TYPE_CHECKING:
21    from music_assistant_models.config_entries import ProviderConfig
22    from music_assistant_models.provider import ProviderManifest
23
24    from music_assistant import MusicAssistant
25    from music_assistant.models import ProviderInstanceType
26
27SUPPORTED_FEATURES = {
28    ProviderFeature.SYNC_PLAYERS,
29}
30
31
32async def setup(
33    mass: MusicAssistant, manifest: ProviderManifest, config: ProviderConfig
34) -> ProviderInstanceType:
35    """Initialize provider(instance) with given configuration."""
36    return SqueezelitePlayerProvider(mass, manifest, config, SUPPORTED_FEATURES)
37
38
39async def get_config_entries(
40    mass: MusicAssistant,
41    instance_id: str | None = None,
42    action: str | None = None,
43    values: dict[str, ConfigValueType] | None = None,
44) -> tuple[ConfigEntry, ...]:
45    """
46    Return Config entries to setup this provider.
47
48    instance_id: id of an existing provider instance (None if new instance setup).
49    action: [optional] action key called from config entries UI.
50    values: the (intermediate) raw values for config entries sent with the action.
51    """
52    # ruff: noqa: ARG001
53    return (
54        ConfigEntry(
55            key=CONF_CLI_TELNET_PORT,
56            type=ConfigEntryType.INTEGER,
57            default_value=9090,
58            label="Classic Squeezebox CLI Port",
59            description="Some slimproto based players require the presence of the telnet CLI "
60            " to request more information. \n\n"
61            "By default this CLI is hosted on port 9090 but some players also accept "
62            "a different port. Set to 0 to disable this functionality.\n\n"
63            "Commands allowed on this interface are very limited and just enough to satisfy "
64            "player compatibility, so security risks are minimized to practically zero."
65            "You may safely disable this option if you have no players that rely on this feature "
66            "or you dont care about the additional metadata.",
67            advanced=True,
68        ),
69        ConfigEntry(
70            key=CONF_CLI_JSON_PORT,
71            type=ConfigEntryType.INTEGER,
72            default_value=9000,
73            label="JSON-RPC CLI/API Port",
74            description="Some slimproto based players require the presence of the JSON-RPC "
75            "API from LMS to request more information. For example to fetch the album cover "
76            "and other metadata. \n\n"
77            "This JSON-RPC API is compatible with Logitech Media Server but not all commands "
78            "are implemented. Just enough to satisfy player compatibility. \n\n"
79            "By default this JSON CLI is hosted on port 9000 but most players also accept "
80            "it on a different port. Set to 0 to disable this functionality.\n\n"
81            "You may safely disable this option if you have no players that rely on this feature "
82            "or you dont care about the additional metadata.",
83            advanced=True,
84        ),
85        ConfigEntry(
86            key=CONF_DISCOVERY,
87            type=ConfigEntryType.BOOLEAN,
88            default_value=True,
89            label="Enable Discovery server",
90            description="Broadcast discovery packets for slimproto clients to automatically "
91            "discover and connect to this server. \n\n"
92            "You may want to disable this feature if you are running multiple slimproto servers "
93            "on your network and/or you don't want clients to auto connect to this server.",
94            advanced=True,
95        ),
96        ConfigEntry(
97            key=CONF_PORT,
98            type=ConfigEntryType.INTEGER,
99            default_value=DEFAULT_SLIMPROTO_PORT,
100            label="Slimproto port",
101            description="The TCP/UDP port to run the slimproto sockets server. "
102            "The default is 3483 and using a different port is not supported by "
103            "hardware squeezebox players. Only adjust this port if you want to "
104            "use other slimproto based servers side by side with (squeezelite) software players.",
105        ),
106    )
107