feat: Move tagmode setting to config.json, remove playlistdb settings
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 4m35s
Check code formatting / Check-C-Format (push) Successful in 7s
Check code formatting / Check-Python-Flake8 (push) Successful in 9s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 6s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 10s
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 4m35s
Check code formatting / Check-C-Format (push) Successful in 7s
Check code formatting / Check-Python-Flake8 (push) Successful in 9s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 6s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 10s
Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
This commit is contained in:
@@ -51,7 +51,7 @@ class PlayerApp:
|
|||||||
self.playlist_db = deps.playlistdb(self)
|
self.playlist_db = deps.playlistdb(self)
|
||||||
self.hwconfig = deps.hwconfig(self)
|
self.hwconfig = deps.hwconfig(self)
|
||||||
self.leds = deps.leds(self)
|
self.leds = deps.leds(self)
|
||||||
self.tag_mode = self.playlist_db.getSetting('tagmode')
|
self.tag_mode = self.config.get_tagmode()
|
||||||
self.playing_tag = None
|
self.playing_tag = None
|
||||||
self.playlist = None
|
self.playlist = None
|
||||||
self.buttons = deps.buttons(self) if deps.buttons is not None else None
|
self.buttons = deps.buttons(self) if deps.buttons is not None else None
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ class Configuration:
|
|||||||
'VOLDOWN': 2,
|
'VOLDOWN': 2,
|
||||||
'PREV': None,
|
'PREV': None,
|
||||||
'NEXT': 1,
|
'NEXT': 1,
|
||||||
}
|
},
|
||||||
|
'TAGMODE': 'tagremains'
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, config_path='/config.json'):
|
def __init__(self, config_path='/config.json'):
|
||||||
@@ -72,6 +73,9 @@ class Configuration:
|
|||||||
def get_button_map(self) -> Mapping[str, int | None]:
|
def get_button_map(self) -> Mapping[str, int | None]:
|
||||||
return self._get('BUTTON_MAP')
|
return self._get('BUTTON_MAP')
|
||||||
|
|
||||||
|
def get_tagmode(self) -> str:
|
||||||
|
return self._get('TAGMODE')
|
||||||
|
|
||||||
# For the web API
|
# For the web API
|
||||||
def get_config(self) -> Mapping[str, Any]:
|
def get_config(self) -> Mapping[str, Any]:
|
||||||
return self.config
|
return self.config
|
||||||
@@ -87,5 +91,7 @@ class Configuration:
|
|||||||
|
|
||||||
def set_config(self, config):
|
def set_config(self, config):
|
||||||
self._validate(self.DEFAULT_CONFIG, config)
|
self._validate(self.DEFAULT_CONFIG, config)
|
||||||
|
if 'TAGMODE' in config and config['TAGMODE'] not in ['tagremains', 'tagstartstop']:
|
||||||
|
raise ValueError("Invalid TAGMODE: Must be 'tagremains' or 'tagstartstop'")
|
||||||
self.config = config
|
self.config = config
|
||||||
self._save()
|
self._save()
|
||||||
|
|||||||
@@ -31,9 +31,6 @@ class BTreeDB(IPlaylistDB):
|
|||||||
PERSIST_NO = b'no'
|
PERSIST_NO = b'no'
|
||||||
PERSIST_TRACK = b'track'
|
PERSIST_TRACK = b'track'
|
||||||
PERSIST_OFFSET = b'offset'
|
PERSIST_OFFSET = b'offset'
|
||||||
DEFAULT_SETTINGS = {
|
|
||||||
b'tagmode': b'tagremains'
|
|
||||||
}
|
|
||||||
|
|
||||||
class Playlist(IPlaylist):
|
class Playlist(IPlaylist):
|
||||||
def __init__(self, parent: "BTreeDB", tag: bytes, pos: int, persist, shuffle):
|
def __init__(self, parent: "BTreeDB", tag: bytes, pos: int, persist, shuffle):
|
||||||
@@ -282,11 +279,6 @@ class BTreeDB(IPlaylistDB):
|
|||||||
self._savePlaylist(tag, entries, persist, shuffle)
|
self._savePlaylist(tag, entries, persist, shuffle)
|
||||||
return self.getPlaylistForTag(tag)
|
return self.getPlaylistForTag(tag)
|
||||||
|
|
||||||
def getSetting(self, key: bytes | str) -> str:
|
|
||||||
if type(key) is str:
|
|
||||||
key = key.encode()
|
|
||||||
return self.db.get(b'settings/' + key, self.DEFAULT_SETTINGS[key]).decode()
|
|
||||||
|
|
||||||
def validate(self, dump=False):
|
def validate(self, dump=False):
|
||||||
"""
|
"""
|
||||||
Validate the structure of the playlist database.
|
Validate the structure of the playlist database.
|
||||||
@@ -306,8 +298,7 @@ class BTreeDB(IPlaylistDB):
|
|||||||
fail(f'Malformed key {k!r}')
|
fail(f'Malformed key {k!r}')
|
||||||
continue
|
continue
|
||||||
if fields[0] == b'settings':
|
if fields[0] == b'settings':
|
||||||
val = self.db[k].decode()
|
# Legacy, not used any more
|
||||||
print(f'Setting {fields[1].decode()} = {val}')
|
|
||||||
continue
|
continue
|
||||||
if last_tag != fields[0]:
|
if last_tag != fields[0]:
|
||||||
last_tag = fields[0]
|
last_tag = fields[0]
|
||||||
|
|||||||
@@ -136,6 +136,9 @@ class FakeConfig:
|
|||||||
def get_tag_timeout(self):
|
def get_tag_timeout(self):
|
||||||
return 5
|
return 5
|
||||||
|
|
||||||
|
def get_tagmode(self):
|
||||||
|
return 'tagremains'
|
||||||
|
|
||||||
|
|
||||||
def fake_open(filename, mode):
|
def fake_open(filename, mode):
|
||||||
return FakeFile(filename, mode)
|
return FakeFile(filename, mode)
|
||||||
@@ -226,18 +229,16 @@ def test_playlist_unknown_tag(micropythonify, faketimermanager, monkeypatch):
|
|||||||
|
|
||||||
|
|
||||||
def test_tagmode_startstop(micropythonify, faketimermanager, monkeypatch):
|
def test_tagmode_startstop(micropythonify, faketimermanager, monkeypatch):
|
||||||
class MyFakePlaylistDb(FakePlaylistDb):
|
class FakeStartStopConfig(FakeConfig):
|
||||||
def __init__(self, tracklist=[b'test/path.mp3']):
|
def __init__(self):
|
||||||
super().__init__(tracklist)
|
super().__init__()
|
||||||
|
|
||||||
def getSetting(self, key: bytes | str):
|
def get_tagmode(self):
|
||||||
if key == 'tagmode':
|
return 'tagstartstop'
|
||||||
return 'tagstartstop'
|
|
||||||
return None
|
|
||||||
|
|
||||||
fake_db = MyFakePlaylistDb()
|
fake_db = FakePlaylistDb([b'test/path.mp3'])
|
||||||
fake_mp3 = FakeMp3Player()
|
fake_mp3 = FakeMp3Player()
|
||||||
deps = _makedeps(mp3player=fake_mp3, playlistdb=fake_db)
|
deps = _makedeps(mp3player=fake_mp3, playlistdb=fake_db, config=FakeStartStopConfig)
|
||||||
app.PlayerApp(deps)
|
app.PlayerApp(deps)
|
||||||
with monkeypatch.context() as m:
|
with monkeypatch.context() as m:
|
||||||
m.setattr(builtins, 'open', fake_open)
|
m.setattr(builtins, 'open', fake_open)
|
||||||
@@ -264,16 +265,7 @@ def test_tagmode_startstop(micropythonify, faketimermanager, monkeypatch):
|
|||||||
|
|
||||||
|
|
||||||
def test_tagmode_remains(micropythonify, faketimermanager, monkeypatch):
|
def test_tagmode_remains(micropythonify, faketimermanager, monkeypatch):
|
||||||
class MyFakePlaylistDb(FakePlaylistDb):
|
fake_db = FakePlaylistDb([b'test/path.mp3'])
|
||||||
def __init__(self, tracklist=[b'test/path.mp3']):
|
|
||||||
super().__init__(tracklist)
|
|
||||||
|
|
||||||
def getSetting(self, key: bytes | str):
|
|
||||||
if key == 'tagmode':
|
|
||||||
return 'tagremains'
|
|
||||||
return None
|
|
||||||
|
|
||||||
fake_db = MyFakePlaylistDb()
|
|
||||||
fake_mp3 = FakeMp3Player()
|
fake_mp3 = FakeMp3Player()
|
||||||
deps = _makedeps(mp3player=fake_mp3, playlistdb=fake_db)
|
deps = _makedeps(mp3player=fake_mp3, playlistdb=fake_db)
|
||||||
app.PlayerApp(deps)
|
app.PlayerApp(deps)
|
||||||
|
|||||||
Reference in New Issue
Block a user