music-assistant-server

2.2 KBPY
__init__.py
2.2 KB66 lines • python
1"""AirPlay Player provider for Music Assistant."""
2
3from __future__ import annotations
4
5from typing import TYPE_CHECKING
6
7from music_assistant_models.config_entries import ConfigEntry, ProviderConfig
8from music_assistant_models.enums import ConfigEntryType, ProviderFeature
9from music_assistant_models.provider import ProviderManifest
10
11from music_assistant.mass import MusicAssistant
12from music_assistant.providers.airplay.constants import (
13    CONF_ENABLE_LATE_JOIN,
14    ENABLE_LATE_JOIN_DEFAULT,
15)
16
17from .provider import AirPlayProvider
18
19if TYPE_CHECKING:
20    from music_assistant_models.config_entries import ConfigValueType, ProviderConfig
21    from music_assistant_models.provider import ProviderManifest
22
23    from music_assistant.models import ProviderInstanceType
24
25SUPPORTED_FEATURES = {
26    ProviderFeature.SYNC_PLAYERS,
27}
28
29
30async def get_config_entries(
31    mass: MusicAssistant,
32    instance_id: str | None = None,
33    action: str | None = None,
34    values: dict[str, ConfigValueType] | None = None,
35) -> tuple[ConfigEntry, ...]:
36    """
37    Return Config entries to setup this provider.
38
39    instance_id: id of an existing provider instance (None if new instance setup).
40    action: [optional] action key called from config entries UI.
41    values: the (intermediate) raw values for config entries sent with the action.
42    """
43    # ruff: noqa: ARG001
44    return (
45        ConfigEntry(
46            key=CONF_ENABLE_LATE_JOIN,
47            type=ConfigEntryType.BOOLEAN,
48            default_value=ENABLE_LATE_JOIN_DEFAULT,
49            label="Enable late joining",
50            description=(
51                "Allow the player to join an existing AirPlay stream instead of "
52                "restarting the whole stream. \n NOTE: may not work in all conditions. "
53                "If you experience issues or players are not fully in sync, disable this option. \n"
54                "Also note that a late joining player may take a few seconds to catch up."
55            ),
56            category="protocol_generic",
57        ),
58    )
59
60
61async def setup(
62    mass: MusicAssistant, manifest: ProviderManifest, config: ProviderConfig
63) -> ProviderInstanceType:
64    """Initialize provider(instance) with given configuration."""
65    return AirPlayProvider(mass, manifest, config, SUPPORTED_FEATURES)
66