-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathdefaults.py
More file actions
184 lines (173 loc) Β· 9.87 KB
/
defaults.py
File metadata and controls
184 lines (173 loc) Β· 9.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import os
from time import time
from shutil import copy
from enum import Enum
from typing import List, Dict, Set, Union, Optional, Callable
from amplipi import models
MUTE_ALL_ID = 10000
LAST_PRESET_ID = 9999
AUX_STREAM_ID = 995
RCAs = [996, 997, 998, 999]
LMS_DEFAULTS = [1000, 1001, 1002, 1003]
USER_CONFIG_DIR = os.path.join(os.path.expanduser('~'), '.config', 'amplipi')
DEFAULT_CONFIG = { # This is the system state response that will come back from the amplipi box
"version": 1,
"sources": [ # this is an array of source objects, each has an id, name, type specifying whether source comes from a local (like RCA) or streaming input like pandora
{"id": 0, "name": "Output 1", "input": ""},
{"id": 1, "name": "Output 2", "input": ""},
{"id": 2, "name": "Output 3", "input": ""},
{"id": 3, "name": "Output 4", "input": ""},
],
# NOTE: streams and groups seem like they should be stored as dictionaries with integer keys
# this does not make sense because JSON only allows string based keys
"streams": [
{"id": AUX_STREAM_ID, "name": "Aux", "type": "aux", "browsable": False, "disabled": False},
{"id": RCAs[0], "name": "Input 1", "type": "rca", "index": 0, "browsable": False, "disabled": False},
{"id": RCAs[1], "name": "Input 2", "type": "rca", "index": 1, "browsable": False, "disabled": False},
{"id": RCAs[2], "name": "Input 3", "type": "rca", "index": 2, "browsable": False, "disabled": False},
{"id": RCAs[3], "name": "Input 4", "type": "rca", "index": 3, "browsable": False, "disabled": False},
{"id": 1000, "name": "Groove Salad", "type": "internetradio", "url": "http://ice6.somafm.com/groovesalad-32-aac",
"logo": "https://somafm.com/img3/groovesalad-400.jpg", "browsable": False, "disabled": False},
{"id": 1001, "name": "AmpliPro 1", "type": "spotify", "disabled": False, "browsable": False},
{"id": 1002, "name": "AmpliPro 2", "type": "spotify", "disabled": False, "browsable": False},
{"id": 1003, "name": "AmpliPro 1", "type": "airplay", "disabled": False, "ap2": False, "browsable": False},
{"id": 1004, "name": "AmpliPro 2", "type": "airplay", "disabled": False, "ap2": True, "browsable": False}
],
"zones": [ # this is an array of zones, array length depends on # of boxes connected
{"id": 0, "name": "Zone 1", "source_id": 0, "mute": True, "disabled": False,
"vol_f": models.MIN_VOL_F, "vol_f_overflow": 0.0, "vol_min": models.MIN_VOL_DB, "vol_max": models.MAX_VOL_DB},
{"id": 1, "name": "Zone 2", "source_id": 0, "mute": True, "disabled": False,
"vol_f": models.MIN_VOL_F, "vol_f_overflow": 0.0, "vol_min": models.MIN_VOL_DB, "vol_max": models.MAX_VOL_DB},
{"id": 2, "name": "Zone 3", "source_id": 0, "mute": True, "disabled": False,
"vol_f": models.MIN_VOL_F, "vol_f_overflow": 0.0, "vol_min": models.MIN_VOL_DB, "vol_max": models.MAX_VOL_DB},
{"id": 3, "name": "Zone 4", "source_id": 0, "mute": True, "disabled": False,
"vol_f": models.MIN_VOL_F, "vol_f_overflow": 0.0, "vol_min": models.MIN_VOL_DB, "vol_max": models.MAX_VOL_DB},
{"id": 4, "name": "Zone 5", "source_id": 0, "mute": True, "disabled": False,
"vol_f": models.MIN_VOL_F, "vol_f_overflow": 0.0, "vol_min": models.MIN_VOL_DB, "vol_max": models.MAX_VOL_DB},
{"id": 5, "name": "Zone 6", "source_id": 0, "mute": True, "disabled": False,
"vol_f": models.MIN_VOL_F, "vol_f_overflow": 0.0, "vol_min": models.MIN_VOL_DB, "vol_max": models.MAX_VOL_DB},
],
"groups": [
],
"presets": [{
# NOTE: additional zones are added automatically to this preset
"id": MUTE_ALL_ID,
"name": "Mute All",
"state": {
"zones": [
{"id": 0, "mute": True},
{"id": 1, "mute": True},
{"id": 2, "mute": True},
{"id": 3, "mute": True},
{"id": 4, "mute": True},
{"id": 5, "mute": True},
]
}
}]
}
STREAMER_CONFIG = { # This is the system state response that will come back from the amplipi box
"sources": [ # this is an array of source objects, each has an id, name, type specifying whether source comes from a local (like RCA) or streaming input like pandora
{"id": 0, "name": "Output 1", "input": ""},
{"id": 1, "name": "Output 2", "input": ""},
{"id": 2, "name": "Output 3", "input": ""},
{"id": 3, "name": "Output 4", "input": ""},
],
"streams": [
{"id": AUX_STREAM_ID, "name": "Aux", "type": "aux", "browsable": False, "disabled": False},
{"id": 1000, "name": "Groove Salad", "type": "internetradio", "url": "http://ice6.somafm.com/groovesalad-32-aac",
"logo": "https://somafm.com/img3/groovesalad-400.jpg", "browsable": False, "disabled": False},
{"id": 1001, "name": "AmpliPro 1", "type": "spotify", "disabled": False, "browsable": False},
{"id": 1002, "name": "AmpliPro 2", "type": "spotify", "disabled": False, "browsable": False},
{"id": 1003, "name": "AmpliPro 1", "type": "airplay", "disabled": False, "ap2": False, "browsable": False},
{"id": 1004, "name": "AmpliPro 2", "type": "airplay", "disabled": False, "ap2": True, "browsable": False}
],
"zones": [ # this is an array of zones, array length depends on # of boxes connected
],
"groups": [
],
"presets": [
]
}
DEFAULT_LMS_CONFIG = { # This is the system state response that will come back from the amplipi box
"sources": [ # this is an array of source objects, each has an id, name, type specifying whether source comes from a local (like RCA) or streaming input like pandora
{"id": 1, "name": "Input 1", "input": f"stream={LMS_DEFAULTS[0]}"},
{"id": 2, "name": "Input 2", "input": f"stream={LMS_DEFAULTS[1]}"},
{"id": 3, "name": "Input 3", "input": f"stream={LMS_DEFAULTS[2]}"},
{"id": 4, "name": "Input 4", "input": f"stream={LMS_DEFAULTS[3]}"},
],
# NOTE: streams and groups seem like they should be stored as dictionaries with integer keys
# this does not make sense because JSON only allows string based keys
"streams": [
{"id": AUX_STREAM_ID, "name": "Aux", "type": "aux", "browsable": False, "disabled": False},
{"id": RCAs[0], "name": "Input 1", "type": "rca", "index": 0, "browsable": False, "disabled": False},
{"id": RCAs[1], "name": "Input 2", "type": "rca", "index": 1, "browsable": False, "disabled": False},
{"id": RCAs[2], "name": "Input 3", "type": "rca", "index": 2, "browsable": False, "disabled": False},
{"id": RCAs[3], "name": "Input 4", "type": "rca", "index": 3, "browsable": False, "disabled": False},
{"id": LMS_DEFAULTS[0], "name": "Music 1", "type": "lms", "browsable": False, "server": "localhost"},
{"id": LMS_DEFAULTS[1], "name": "Music 2", "type": "lms", "browsable": False, "server": "localhost"},
{"id": LMS_DEFAULTS[2], "name": "Music 3", "type": "lms", "browsable": False, "server": "localhost"},
{"id": LMS_DEFAULTS[3], "name": "Music 4", "type": "lms", "browsable": False, "server": "localhost"},
],
"zones": [ # this is an array of zones, array length depends on # of boxes connected
{"id": 0, "name": "Zone 1", "source_id": 0, "mute": True, "disabled": False,
"vol_f": models.MIN_VOL_F, "vol_min": models.MIN_VOL_DB, "vol_max": models.MAX_VOL_DB},
{"id": 1, "name": "Zone 2", "source_id": 0, "mute": True, "disabled": False,
"vol_f": models.MIN_VOL_F, "vol_min": models.MIN_VOL_DB, "vol_max": models.MAX_VOL_DB},
{"id": 2, "name": "Zone 3", "source_id": 0, "mute": True, "disabled": False,
"vol_f": models.MIN_VOL_F, "vol_min": models.MIN_VOL_DB, "vol_max": models.MAX_VOL_DB},
{"id": 3, "name": "Zone 4", "source_id": 0, "mute": True, "disabled": False,
"vol_f": models.MIN_VOL_F, "vol_min": models.MIN_VOL_DB, "vol_max": models.MAX_VOL_DB},
{"id": 4, "name": "Zone 5", "source_id": 0, "mute": True, "disabled": False,
"vol_f": models.MIN_VOL_F, "vol_min": models.MIN_VOL_DB, "vol_max": models.MAX_VOL_DB},
{"id": 5, "name": "Zone 6", "source_id": 0, "mute": True, "disabled": False,
"vol_f": models.MIN_VOL_F, "vol_min": models.MIN_VOL_DB, "vol_max": models.MAX_VOL_DB},
],
"groups": [
],
"presets": [{
# NOTE: additional zones are added automatically to this preset"id": MUTE_ALL_ID,
"name": "Mute All",
"state": {
"zones": [
{"id": 0, "mute": True},
{"id": 1, "mute": True},
{"id": 2, "mute": True},
{"id": 3, "mute": True},
{"id": 4, "mute": True},
{"id": 5, "mute": True},
]
}
}]
}
STREAMER_LMS_CONFIG = { # This is the system state response that will come back from the amplipi box
"sources": [ # this is an array of source objects, each has an id, name, type specifying whether source comes from a local (like RCA) or streaming input like pandora
{"id": 1, "name": "Output 1", "input": f"stream={LMS_DEFAULTS[0]}"},
{"id": 2, "name": "Output 2", "input": f"stream={LMS_DEFAULTS[1]}"},
{"id": 3, "name": "Output 3", "input": f"stream={LMS_DEFAULTS[2]}"},
{"id": 4, "name": "Output 4", "input": f"stream={LMS_DEFAULTS[3]}"},
],
"streams": [
{"id": AUX_STREAM_ID, "name": "Aux", "type": "aux", "browsable": False, "disabled": False},
{"id": LMS_DEFAULTS[0], "name": "Music 1", "type": "lms", "browsable": False, "server": "localhost"},
{"id": LMS_DEFAULTS[1], "name": "Music 2", "type": "lms", "browsable": False, "server": "localhost"},
{"id": LMS_DEFAULTS[2], "name": "Music 3", "type": "lms", "browsable": False, "server": "localhost"},
{"id": LMS_DEFAULTS[3], "name": "Music 4", "type": "lms", "browsable": False, "server": "localhost"},
],
"zones": [ # this is an array of zones, array length depends on # of boxes connected
],
"groups": [
],
"presets": [
]
}
def default_config(is_streamer: bool, lms_mode: bool) -> dict:
""" Given a little bit of system state, return the correct default
configuration for a given appliance.
"""
if not lms_mode and is_streamer:
return STREAMER_CONFIG
elif lms_mode and is_streamer:
return STREAMER_LMS_CONFIG
elif lms_mode and not is_streamer:
return DEFAULT_LMS_CONFIG
return DEFAULT_CONFIG