diff --git a/haphilipsjs/__init__.py b/haphilipsjs/__init__.py index 44b08c5..dc7d87e 100644 --- a/haphilipsjs/__init__.py +++ b/haphilipsjs/__init__.py @@ -66,7 +66,7 @@ HTTP_PORT = 1925 HTTPS_PORT = 1926 MAXIMUM_ITEMS_IN_REQUEST = 50 - +IGNORED_JSON_RESPONSES = {"", "Context Service not started", "}"} def hmac_signature(key: bytes, timestamp: str, data: str): """Calculate a timestamped signature.""" @@ -101,7 +101,7 @@ def cbc_encode(key: bytes, data: str): def decode_xtv_json(text: str): - if text == "" or text == "}": + if text in IGNORED_JSON_RESPONSES: LOG.debug("Ignoring invalid json %s", text) return {} diff --git a/tests/test_v6.py b/tests/test_v6.py index 7d496f3..5a6d2ad 100644 --- a/tests/test_v6.py +++ b/tests/test_v6.py @@ -575,6 +575,7 @@ def mock_strings(request: StringsRequest, response: Strings): async def test_buggy_json(): assert haphilipsjs.decode_xtv_json("") == {} assert haphilipsjs.decode_xtv_json("}") == {} + assert haphilipsjs.decode_xtv_json("Context Service not started") == {} assert haphilipsjs.decode_xtv_json('{,"a":{}}') == {"a": {}} assert haphilipsjs.decode_xtv_json('{"a":{},}') == {"a": {}} assert haphilipsjs.decode_xtv_json('{"a":{},,,"b":{}}') == {"a": {}, "b": {}}