Format zwave_js dump as json (#46792)

This commit is contained in:
Raman Gupta 2021-02-19 18:44:15 -05:00 committed by GitHub
parent 4d23ffacd1
commit 47dcd2bf32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -281,9 +281,9 @@ class DumpView(HomeAssistantView):
msgs = await dump.dump_msgs(entry.data[CONF_URL], async_get_clientsession(hass))
return web.Response(
body="\n".join(json.dumps(msg) for msg in msgs) + "\n",
body=json.dumps(msgs, indent=2) + "\n",
headers={
hdrs.CONTENT_TYPE: "application/jsonl",
hdrs.CONTENT_DISPOSITION: 'attachment; filename="zwave_js_dump.jsonl"',
hdrs.CONTENT_TYPE: "application/json",
hdrs.CONTENT_DISPOSITION: 'attachment; filename="zwave_js_dump.json"',
},
)

View File

@ -1,4 +1,5 @@
"""Test the Z-Wave JS Websocket API."""
import json
from unittest.mock import patch
from zwave_js_server.event import Event
@ -164,7 +165,7 @@ async def test_dump_view(integration, hass_client):
):
resp = await client.get(f"/api/zwave_js/dump/{integration.entry_id}")
assert resp.status == 200
assert await resp.text() == '{"hello": "world"}\n{"second": "msg"}\n'
assert json.loads(await resp.text()) == [{"hello": "world"}, {"second": "msg"}]
async def test_dump_view_invalid_entry_id(integration, hass_client):