feat(media): SmtcController.resume() stellt nur eigene Pausen wieder her
This commit is contained in:
@@ -149,3 +149,82 @@ async def test_pause_logs_and_continues_when_session_fails(monkeypatch, caplog):
|
||||
good.try_pause_async.assert_awaited_once()
|
||||
assert controller._paused == ["Spotify"]
|
||||
assert any("broken" in r.message for r in caplog.records)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resume_with_empty_paused_list_is_noop(monkeypatch):
|
||||
from whisper_local.media._smtc import SmtcController
|
||||
|
||||
controller = SmtcController()
|
||||
controller._paused = []
|
||||
ensure = AsyncMock()
|
||||
monkeypatch.setattr(controller, "_ensure_manager", ensure)
|
||||
|
||||
await controller.resume()
|
||||
|
||||
ensure.assert_not_awaited()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resume_plays_only_previously_paused(monkeypatch):
|
||||
from whisper_local.media._smtc import SmtcController
|
||||
|
||||
spotify = _make_session("Spotify", PAUSED)
|
||||
edge = _make_session("msedge", PAUSED)
|
||||
controller = SmtcController()
|
||||
controller._paused = ["Spotify"]
|
||||
monkeypatch.setattr(
|
||||
controller,
|
||||
"_ensure_manager",
|
||||
AsyncMock(return_value=_make_manager([spotify, edge])),
|
||||
)
|
||||
|
||||
await controller.resume()
|
||||
|
||||
spotify.try_play_async.assert_awaited_once()
|
||||
edge.try_play_async.assert_not_awaited()
|
||||
assert controller._paused == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resume_skips_disappeared_session(monkeypatch, caplog):
|
||||
from whisper_local.media._smtc import SmtcController
|
||||
|
||||
still_there = _make_session("Spotify", PAUSED)
|
||||
controller = SmtcController()
|
||||
controller._paused = ["gone_app", "Spotify"]
|
||||
monkeypatch.setattr(
|
||||
controller,
|
||||
"_ensure_manager",
|
||||
AsyncMock(return_value=_make_manager([still_there])),
|
||||
)
|
||||
|
||||
with caplog.at_level("WARNING"):
|
||||
await controller.resume()
|
||||
|
||||
still_there.try_play_async.assert_awaited_once()
|
||||
assert controller._paused == []
|
||||
assert any("gone_app" in r.message for r in caplog.records)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resume_logs_and_continues_when_session_fails(monkeypatch, caplog):
|
||||
from whisper_local.media._smtc import SmtcController
|
||||
|
||||
broken = _make_session("broken", PAUSED)
|
||||
broken.try_play_async = AsyncMock(side_effect=RuntimeError("Verbindung verloren"))
|
||||
good = _make_session("Spotify", PAUSED)
|
||||
controller = SmtcController()
|
||||
controller._paused = ["broken", "Spotify"]
|
||||
monkeypatch.setattr(
|
||||
controller,
|
||||
"_ensure_manager",
|
||||
AsyncMock(return_value=_make_manager([broken, good])),
|
||||
)
|
||||
|
||||
with caplog.at_level("WARNING"):
|
||||
await controller.resume()
|
||||
|
||||
good.try_play_async.assert_awaited_once()
|
||||
assert controller._paused == []
|
||||
assert any("broken" in r.message for r in caplog.records)
|
||||
|
||||
@@ -67,4 +67,27 @@ class SmtcController:
|
||||
self._paused = paused
|
||||
|
||||
async def resume(self) -> None:
|
||||
pass
|
||||
if not self._paused:
|
||||
return
|
||||
try:
|
||||
manager = await self._ensure_manager()
|
||||
current = {
|
||||
s.source_app_user_model_id: s for s in manager.get_sessions()
|
||||
}
|
||||
except Exception as e:
|
||||
logger.warning("SMTC nicht erreichbar beim Fortsetzen: %s", e)
|
||||
self._paused = []
|
||||
return
|
||||
to_resume = self._paused
|
||||
self._paused = []
|
||||
for aumid in to_resume:
|
||||
session = current.get(aumid)
|
||||
if session is None:
|
||||
logger.warning(
|
||||
"Session %s nicht mehr vorhanden, wird übersprungen", aumid
|
||||
)
|
||||
continue
|
||||
try:
|
||||
await session.try_play_async()
|
||||
except Exception as e:
|
||||
logger.warning("Konnte Session %s nicht fortsetzen: %s", aumid, e)
|
||||
|
||||
Reference in New Issue
Block a user