music-assistant-server

1.9 KBPY
__init__.py
1.9 KB59 lines • python
1"""
2Sonos Player provider for Music Assistant for speakers running the S2 firmware.
3
4Based on the aiosonos library, which leverages the new websockets API of the Sonos S2 firmware.
5https://github.com/music-assistant/aiosonos
6"""
7
8from __future__ import annotations
9
10import logging
11from typing import TYPE_CHECKING
12
13from music_assistant_models.enums import ProviderFeature
14
15from music_assistant.constants import CONF_ENTRY_MANUAL_DISCOVERY_IPS, VERBOSE_LOG_LEVEL
16
17from .provider import SonosPlayerProvider
18
19if TYPE_CHECKING:
20    from music_assistant_models.config_entries import ConfigEntry, ConfigValueType, ProviderConfig
21    from music_assistant_models.provider import ProviderManifest
22
23    from music_assistant import MusicAssistant
24    from music_assistant.models import ProviderInstanceType
25
26SUPPORTED_FEATURES = {
27    ProviderFeature.SYNC_PLAYERS,
28}
29
30
31async def setup(
32    mass: MusicAssistant, manifest: ProviderManifest, config: ProviderConfig
33) -> ProviderInstanceType:
34    """Initialize provider(instance) with given configuration."""
35    prov = SonosPlayerProvider(mass, manifest, config, SUPPORTED_FEATURES)
36    # set-up aiosonos logging
37    if prov.logger.isEnabledFor(VERBOSE_LOG_LEVEL):
38        logging.getLogger("aiosonos").setLevel(logging.DEBUG)
39    else:
40        logging.getLogger("aiosonos").setLevel(prov.logger.level + 10)
41    return prov
42
43
44async def get_config_entries(
45    mass: MusicAssistant,
46    instance_id: str | None = None,
47    action: str | None = None,
48    values: dict[str, ConfigValueType] | None = None,
49) -> tuple[ConfigEntry, ...]:
50    """
51    Return Config entries to setup this provider.
52
53    instance_id: id of an existing provider instance (None if new instance setup).
54    action: [optional] action key called from config entries UI.
55    values: the (intermediate) raw values for config entries sent with the action.
56    """
57    # ruff: noqa: ARG001
58    return (CONF_ENTRY_MANUAL_DISCOVERY_IPS,)
59