mirror of
https://github.com/deunix-educ/mediadeck.git
synced 2026-11-25 04:39:42 +01:00
Initial commit: MediaDeck web remote for a Linux media PC
Python bridge (aiohttp, single asyncio loop) between a tablet browser and a Linux media PC: MPRIS players, PipeWire audio (pactl), virtual keyboard and touchpad (uinput), power and session control (logind). - Tablet UI with player, audio, touchpad, launchers and system tabs (fr/en) - Launchers stored in SQLite and managed from /admin; raw commands are opt-in (admin.allow_custom_command) - Optional text entry, translated to key presses from the PC's real keyboard layout with libxkbcommon and never through the clipboard (features.text_input, off by default) - Local HTTPS with a private CA restricted by name constraints (make cert) - Token-protected WebSocket and REST API, strict CSP, no JS dependencies Checked: pyright 0 errors, 87 unit tests, browser tests in headless Chromium. Not yet exercised on the real tablet, nor with real uinput key presses. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"""Tests des conversions MPRIS et pactl, sans D-Bus ni serveur audio."""
|
||||
|
||||
import json
|
||||
import unittest
|
||||
|
||||
from dbus_next.signature import Variant
|
||||
|
||||
from mediadeck.audio import parse_sinks
|
||||
from mediadeck.mpris import normalize_metadata, unwrap
|
||||
|
||||
|
||||
class MprisTest(unittest.TestCase):
|
||||
def test_unwrap_nested_variants(self) -> None:
|
||||
value = {"a": Variant("as", ["x", "y"]), "b": Variant("v", Variant("i", 3))}
|
||||
self.assertEqual(unwrap(value), {"a": ["x", "y"], "b": 3})
|
||||
|
||||
def test_normalize_metadata(self) -> None:
|
||||
raw = {
|
||||
"mpris:trackid": Variant("o", "/org/mpris/MediaPlayer2/Track/1"),
|
||||
"mpris:length": Variant("x", 215_000_000),
|
||||
"xesam:title": Variant("s", "Song"),
|
||||
"xesam:artist": Variant("as", ["A", "B"]),
|
||||
"xesam:comment": Variant("as", ["ignored"]),
|
||||
}
|
||||
meta = normalize_metadata(raw)
|
||||
self.assertEqual(meta["artist"], "A, B")
|
||||
self.assertEqual(meta["length"], 215_000_000)
|
||||
self.assertEqual(meta["trackid"], "/org/mpris/MediaPlayer2/Track/1")
|
||||
self.assertNotIn("comment", meta)
|
||||
|
||||
def test_missing_length_defaults_to_zero(self) -> None:
|
||||
self.assertEqual(normalize_metadata({})["length"], 0)
|
||||
|
||||
|
||||
class PactlTest(unittest.TestCase):
|
||||
def test_parse_sinks_average_volume(self) -> None:
|
||||
raw = json.dumps(
|
||||
[
|
||||
{
|
||||
"name": "alsa_output.hdmi",
|
||||
"description": "HDMI TV",
|
||||
"mute": False,
|
||||
"volume": {
|
||||
"front-left": {"value": 26214, "value_percent": "40%", "db": "-23.88 dB"},
|
||||
"front-right": {"value": 32768, "value_percent": "50%", "db": "-18.06 dB"},
|
||||
},
|
||||
},
|
||||
{"name": "bt", "description": "", "mute": True, "volume": {}},
|
||||
]
|
||||
)
|
||||
sinks = parse_sinks(raw)
|
||||
self.assertEqual(sinks[0]["volume"], 0.45)
|
||||
self.assertFalse(sinks[0]["muted"])
|
||||
# Description vide : repli sur le nom
|
||||
self.assertEqual(sinks[1]["description"], "bt")
|
||||
self.assertTrue(sinks[1]["muted"])
|
||||
self.assertEqual(sinks[1]["volume"], 0.0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user