diff --git a/code/espurna/homeassistant.ino b/code/espurna/homeassistant.ino index 0e0a8cba..a212fa52 100644 --- a/code/espurna/homeassistant.ino +++ b/code/espurna/homeassistant.ino @@ -148,7 +148,7 @@ void _haSendSwitches() { // ----------------------------------------------------------------------------- -void _haDumpConfig(std::function printer) { +void _haDumpConfig(std::function printer, bool wrapJson = false) { #if (LIGHT_PROVIDER != LIGHT_PROVIDER_NONE) || (defined(ITEAD_SLAMPHER)) String type = String("light"); @@ -165,6 +165,10 @@ void _haDumpConfig(std::function printer) { String output; output.reserve(config.measureLength() + 32); + if (wrapJson) { + output += "{\"haConfig\": \""; + } + output += "\n\n" + type + ":\n"; bool first = true; @@ -182,6 +186,10 @@ void _haDumpConfig(std::function printer) { } output += " "; + if (wrapJson) { + output += "\"}"; + } + jsonBuffer.clear(); printer(output); @@ -199,6 +207,10 @@ void _haDumpConfig(std::function printer) { String output; output.reserve(config.measureLength() + 32); + if (wrapJson) { + output += "{\"haConfig\": \""; + } + output += "\n\nsensor:\n"; bool first = true; @@ -218,6 +230,10 @@ void _haDumpConfig(std::function printer) { } output += " "; + if (wrapJson) { + output += "\"}"; + } + jsonBuffer.clear(); printer(output); @@ -324,12 +340,9 @@ void _haLoop() { // TODO check wsConnected after each "printer" call? _haDumpConfig([client_id](String& output) { - output.replace(" ", " "); - output.replace("\n", "
"); - output = String("{\"haConfig\": \"") + output + String("\"}"); wsSend(client_id, output.c_str()); yield(); - }); + }, true); } #endif diff --git a/code/html/custom.js b/code/html/custom.js index 079664bb..3e412de7 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -657,8 +657,10 @@ function doScan() { } function doHAConfig() { - $("#haConfig").html(""); - $("#haConfig").show(); + $("#haConfig") + .text("") + .height(0) + .show(); sendAction("haconfig", {}); return false; } @@ -1368,7 +1370,9 @@ function processData(data) { if ("haConfig" === key) { websock.send("{}"); - $("#haConfig").append(value); + $("#haConfig") + .append(new Text(value)) + .height($("#haConfig")[0].scrollHeight); return; } diff --git a/code/html/index.html b/code/html/index.html index a799d612..935a6007 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -1115,7 +1115,7 @@
- +