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."""