/
/
/
1"""Constants for Sonos S1 Player Provider."""
2
3from __future__ import annotations
4
5from music_assistant_models.enums import PlaybackState, PlayerFeature
6from soco.core import MUSIC_SRC_LINE_IN, MUSIC_SRC_TV
7
8from music_assistant.models.player import PlayerSource
9
10# Configuration Keys
11CONF_NETWORK_SCAN = "network_scan"
12CONF_HOUSEHOLD_ID = "household_id"
13
14# Player Features
15PLAYER_FEATURES = (
16 PlayerFeature.PLAY_MEDIA,
17 PlayerFeature.SET_MEMBERS,
18 PlayerFeature.VOLUME_MUTE,
19 PlayerFeature.VOLUME_SET,
20 PlayerFeature.ENQUEUE,
21 PlayerFeature.GAPLESS_PLAYBACK,
22 PlayerFeature.SELECT_SOURCE,
23)
24
25# Source Mapping
26SOURCE_LINEIN = "Line-in"
27SOURCE_TV = "TV"
28
29# Line-in and TV are the only sources this provider can report or switch to.
30LINEIN_SOURCE_MAPPING = {
31 MUSIC_SRC_TV: SOURCE_TV,
32 MUSIC_SRC_LINE_IN: SOURCE_LINEIN,
33}
34
35LINEIN_SOURCE_IDS = (SOURCE_TV, SOURCE_LINEIN)
36
37PLAYER_SOURCE_MAP = {
38 SOURCE_LINEIN: PlayerSource(
39 id=SOURCE_LINEIN,
40 name="Line-in",
41 passive=False,
42 can_play_pause=False,
43 can_next_previous=False,
44 can_seek=False,
45 ),
46 SOURCE_TV: PlayerSource(
47 id=SOURCE_TV,
48 name="TV",
49 passive=False,
50 can_play_pause=False,
51 can_next_previous=False,
52 can_seek=False,
53 ),
54}
55
56# Playback State Mapping
57PLAYBACK_STATE_MAP = {
58 "PLAYING": PlaybackState.PLAYING,
59 "PAUSED_PLAYBACK": PlaybackState.PAUSED,
60 "STOPPED": PlaybackState.IDLE,
61 "TRANSITIONING": PlaybackState.PLAYING,
62}
63
64# Sonos State Constants
65SONOS_STATE_PLAYING = "PLAYING"
66SONOS_STATE_TRANSITIONING = "TRANSITIONING"
67
68POLL_INTERVAL = 5
69# A speaker that reports TRANSITIONING carries no usable transport state (the coordinator of a
70# group that is still forming reports it for several seconds), so that report is discarded. It is
71# watched closely until it reports a usable state again, instead of leaving the player stale for a
72# full poll interval.
73TRANSITION_POLL_INTERVAL = 1
74
75# Subscription Settings
76SUBSCRIPTION_TIMEOUT = 1200
77SUBSCRIPTION_SERVICES = {
78 "avTransport",
79 "deviceProperties",
80 "renderingControl",
81 "zoneGroupTopology",
82}
83
84# Timing Constants
85DISCOVERY_INTERVAL = 1800
86NEVER_TIME = 0
87RESUB_COOLDOWN_SECONDS = 10.0
88# S1 speakers often drop or delay control requests while busy, so a single failed request
89# is not enough to mark a speaker offline. A failing ping is only trusted once events and
90# polls have both been silent for this long.
91AVAILABILITY_TIMEOUT = 60.0
92# S1 speakers apply a command a moment after acknowledging it, so the resulting state is
93# read back with a short delay instead of trusting the response to the command itself.
94COMMAND_POLL_DELAY = 2
95
96# Position/Duration Keys
97DURATION_SECONDS = "duration_in_s"
98POSITION_SECONDS = "position_in_s"
99
100# UID Constants
101UID_PREFIX = "RINCON_"
102UID_POSTFIX = "01400"
103