From 15b196447d476ce117b35a6e7fa608aebda24c7f Mon Sep 17 00:00:00 2001 From: Carmine Cristallo <5416417+ccristal@users.noreply.github.com> Date: Mon, 19 Oct 2026 09:12:05 +0100 Subject: [PATCH] Log the expected "Failed" metainfo answer at debug level WiiM devices answer getMetaInfo with plain-text "Failed" when nothing is loaded. The player already treats that as empty metainfo, but the JSON helper logged a warning on every poll (thousands overnight while idle). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DBuBhcANHioWShtwB1sTxq --- src/linkplay/utils.py | 6 +++++- tests/linkplay/test_bridge.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/linkplay/utils.py b/src/linkplay/utils.py index 8a22c91..aa0fda3 100644 --- a/src/linkplay/utils.py +++ b/src/linkplay/utils.py @@ -97,7 +97,11 @@ async def session_call_api_json( return json.loads(result) # type: ignore except json.JSONDecodeError as jsonexc: url = API_ENDPOINT.format(endpoint, command) - LOGGER.warning("Unexpected json for %s: %s", url, jsonexc) + # WiiM devices answer "Failed" to getMetaInfo when nothing is loaded + if result == "Failed": + LOGGER.debug("Unexpected json for %s: %s", url, jsonexc) + else: + LOGGER.warning("Unexpected json for %s: %s", url, jsonexc) raise LinkPlayInvalidDataException( message=f"Unexpected JSON ({result}) received from '{url}'", data=result ) from jsonexc diff --git a/tests/linkplay/test_bridge.py b/tests/linkplay/test_bridge.py index 100a8f1..50f5005 100644 --- a/tests/linkplay/test_bridge.py +++ b/tests/linkplay/test_bridge.py @@ -1,5 +1,6 @@ """Test bridge functionality.""" +import logging from typing import Any from unittest.mock import AsyncMock, MagicMock, Mock, patch @@ -565,7 +566,7 @@ async def test_update_status_does_not_trigger_controller_on_no_mode_change(mock_ mock_bridge.device.controller.assert_not_called() -async def test_meta_info_failed_handling(): +async def test_meta_info_failed_handling(caplog: pytest.LogCaptureFixture): """Test that the player handles a failed META_INFO request correctly.""" async def mock_session_call_api_json_side_effect(endpoint, session, command): @@ -601,6 +602,9 @@ async def mock_session_call_api_json_side_effect(endpoint, session, command): # Verify that the mocked function was called with the correct command mock_api.assert_called_with("http://1.2.3.4", None, LinkPlayCommand.META_INFO) + # Verify that the expected "Failed" answer is not logged as a warning + assert not [r for r in caplog.records if r.levelno >= logging.WARNING] + async def test_audio_output_control(): """Test that the player handles a audio output control correctly."""