/
/
/
1"""Constants for Chromecast Player provider."""
2
3from __future__ import annotations
4
5from music_assistant_models.config_entries import ConfigEntry
6from music_assistant_models.enums import ConfigEntryType
7
8from music_assistant.constants import (
9 CONF_ENTRY_FLOW_MODE,
10 CONF_ENTRY_HTTP_PROFILE_DEFAULT_3,
11 CONF_ENTRY_OUTPUT_CODEC,
12 create_sample_rates_config_entry,
13)
14
15MASS_APP_ID = "C35B0678"
16APP_MEDIA_RECEIVER = "CC1AD845"
17SENDSPIN_CAST_APP_ID = "DD107DDB"
18SENDSPIN_CAST_NAMESPACE = "urn:x-cast:sendspin"
19CONF_USE_MASS_APP = "use_mass_app"
20DASHBOARD_NAMESPACE = "urn:x-cast:io.music-assistant.cast"
21
22# Seconds to wait for a Cast receiver to acknowledge an app launch.
23APP_LAUNCH_TIMEOUT = 30.0
24
25# keepalive media the cast receiver plays while showing a dashboard
26DASHBOARD_KEEPALIVE_SUFFIXES = ("/dashboard-keepalive.mp4", "/keepalive.png")
27
28# Interval (seconds) before an unavailable player is re-evaluated as a possible
29# passive multichannel endpoint that should be removed from the setup.
30MULTICHANNEL_RECHECK_INTERVAL = 600
31
32# Devices known to not work with the Sendspin Cast bridge.
33# Tuple of (manufacturer, model) where "*" is a wildcard.
34# These devices will not get a Sendspin bridge, allowing other protocols
35# (e.g. AirPlay bridge) to handle them instead.
36SENDSPIN_CAST_BLOCKLIST: set[tuple[str, str]] = {
37 ("Harman Luxury Audio", "*"),
38 ("*", "HK OMNI ADAPT+AMP"),
39}
40
41CAST_PLAYER_CONFIG_ENTRIES = (
42 CONF_ENTRY_OUTPUT_CODEC,
43 CONF_ENTRY_HTTP_PROFILE_DEFAULT_3,
44 # enable flow mode by default as cast devices handle a continuous
45 # flow stream more reliably than enqueueing individual tracks
46 ConfigEntry.from_dict({**CONF_ENTRY_FLOW_MODE.to_dict(), "default_value": True}),
47 ConfigEntry(
48 key=CONF_USE_MASS_APP,
49 type=ConfigEntryType.BOOLEAN,
50 default_value=True,
51 advanced=True,
52 ),
53)
54
55# originally/officially cast supports 96k sample rate (even for groups)
56# but it seems a (recent?) update broke this ?!
57# For now only set safe default values and let the user try out higher values
58CONF_ENTRY_SAMPLE_RATES_CAST = create_sample_rates_config_entry(
59 max_sample_rate=192000,
60 max_bit_depth=24,
61 safe_max_sample_rate=48000,
62 safe_max_bit_depth=16,
63)
64CONF_ENTRY_SAMPLE_RATES_CAST_GROUP = create_sample_rates_config_entry(
65 max_sample_rate=96000,
66 max_bit_depth=24,
67 safe_max_sample_rate=48000,
68 safe_max_bit_depth=16,
69)
70
71# Measured defaults for known Cast models.
72CAST_MODEL_STATIC_DELAY: dict[tuple[str, str], int] = {
73 ("Google Inc.", "Google Home Mini"): 330,
74 ("Google Inc.", "Google Nest Mini"): 427,
75 ("Google Inc.", "Chromecast Audio"): 335,
76 ("Google Inc.", "Google Nest Hub"): 188,
77}
78CAST_FALLBACK_STATIC_DELAY = 330
79
80
81def get_cast_model_static_delay(manufacturer: str, model: str) -> int:
82 """
83 Look up the default static delay for a Cast device model.
84
85 :param manufacturer: Device manufacturer (e.g., "Google Inc.").
86 :param model: Device model name (e.g., "Google Nest Mini").
87 """
88 return CAST_MODEL_STATIC_DELAY.get((manufacturer, model), CAST_FALLBACK_STATIC_DELAY)
89