Skip to content

Commit 707beae

Browse files
committed
fix: correct invalid json on TPN256E
1 parent 91ff1c6 commit 707beae

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

haphilipsjs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def decode_xtv_json(text: str):
111111
data = json.loads(text)
112112
except json.decoder.JSONDecodeError:
113113
LOG.debug("Invalid json received, trying adjusted version")
114+
text = text.replace('"channelList": { "id": "version", "" }', '"channelList": { "id": "all", "version": "" }')
114115
text = text.replace("{,", "{")
115116
text = text.replace(",}", "}")
116117
while (p := text.find(",,")) >= 0:

tests/test_v6.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,12 @@ async def test_buggy_json():
588588
assert haphilipsjs.decode_xtv_json('{,"a":{}}') == {"a": {}}
589589
assert haphilipsjs.decode_xtv_json('{"a":{},}') == {"a": {}}
590590
assert haphilipsjs.decode_xtv_json('{"a":{},,,"b":{}}') == {"a": {}, "b": {}}
591+
592+
# Invalid data seen on TPN256E
593+
assert haphilipsjs.decode_xtv_json('{ "channelList": { "id": "version", "" } }') == {
594+
"channelList": { "id": "all", "version": "" }
595+
}
596+
591597
with pytest.raises(haphilipsjs.NoneJsonData):
592598
haphilipsjs.decode_xtv_json("Plain text data")
593599

0 commit comments

Comments
 (0)