Browse Source

do html escaping on the client

sensors
Max Prokhorov 5 years ago
parent
commit
e1ddcc533c
3 changed files with 26 additions and 9 deletions
  1. +18
    -5
      code/espurna/homeassistant.ino
  2. +7
    -3
      code/html/custom.js
  3. +1
    -1
      code/html/index.html

+ 18
- 5
code/espurna/homeassistant.ino View File

@ -148,7 +148,7 @@ void _haSendSwitches() {
// -----------------------------------------------------------------------------
void _haDumpConfig(std::function<void(String&)> printer) {
void _haDumpConfig(std::function<void(String&)> 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<void(String&)> 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<void(String&)> printer) {
}
output += " ";
if (wrapJson) {
output += "\"}";
}
jsonBuffer.clear();
printer(output);
@ -199,6 +207,10 @@ void _haDumpConfig(std::function<void(String&)> 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<void(String&)> 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(" ", "&nbsp;");
output.replace("\n", "<br />");
output = String("{\"haConfig\": \"") + output + String("\"}");
wsSend(client_id, output.c_str());
yield();
});
}, true);
}
#endif


+ 7
- 3
code/html/custom.js View File

@ -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;
}


+ 1
- 1
code/html/index.html View File

@ -1115,7 +1115,7 @@
</div>
</div>
<div class="pure-g">
<span class="pure-u-1 terminal" id="haConfig" name="haConfig"></span>
<textarea class="pure-u-1 terminal" id="haConfig" name="haConfig" wrap="off" readonly></textarea>
</div>


Loading…
Cancel
Save