Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/linkplay/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ async def update_status(self) -> None:
MetaInfo, dict[MetaInfoMetaData, str]
] = await self.bridge.json_request(LinkPlayCommand.META_INFO) # type: ignore[assignment]
except LinkPlayInvalidDataException as exc:
if getattr(exc, "data", None) == "Failed":
raw = getattr(exc, "data", None)
if isinstance(raw, str) and raw.strip() in ("", "Failed"):
self.metainfo = {}
else:
raise
Expand Down
6 changes: 5 additions & 1 deletion src/linkplay/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
stripped = result.strip() if result else ""
if stripped in ("", "Failed"):
LOGGER.debug("Non-JSON response for %s: %r", url, stripped)
else:
LOGGER.warning("Unexpected json for %s: %s", url, jsonexc)
raise LinkPlayInvalidDataException(
message=f"Unexpected JSON ({result}) received from '{url}'", data=result
) from jsonexc
Expand Down
26 changes: 26 additions & 0 deletions tests/linkplay/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,32 @@ async def mock_session_call_api_json_side_effect(endpoint, session, command):
mock_api.assert_called_with("http://1.2.3.4", None, LinkPlayCommand.META_INFO)


async def test_meta_info_empty_response_handling():
"""Test that the player handles an empty META_INFO response correctly."""

async def mock_session_call_api_json_side_effect(endpoint, session, command):
if command == LinkPlayCommand.META_INFO:
return ""
return "{}"

with patch(
"linkplay.utils.session_call_api",
new=AsyncMock(side_effect=mock_session_call_api_json_side_effect),
):
mock_bridge = LinkPlayBridge(
endpoint=LinkPlayApiEndpoint(
protocol="http", port=80, endpoint="1.2.3.4", session=None
)
)
mock_bridge.device = MagicMock()
mock_bridge.device.manufacturer = MANUFACTURER_WIIM

player = LinkPlayPlayer(mock_bridge)
await player.update_status()

assert player.metainfo == {}


async def test_audio_output_control():
"""Test that the player handles a audio output control correctly."""

Expand Down