diff --git a/code/espurna/homeassistant.ino b/code/espurna/homeassistant.ino index 593f4cdb..43f47ac3 100644 --- a/code/espurna/homeassistant.ino +++ b/code/espurna/homeassistant.ino @@ -163,7 +163,7 @@ String _haGetConfig() { JsonObject& config = jsonBuffer.createObject(); _haSendSwitch(i, config); - output += type + ":\n"; + output += "\n" + type + ":\n"; bool first = true; for (auto kv : config) { if (first) { @@ -174,7 +174,6 @@ String _haGetConfig() { } output += kv.key + String(": ") + kv.value.as() + String("\n"); } - output += "\n"; jsonBuffer.clear(); @@ -188,7 +187,7 @@ String _haGetConfig() { JsonObject& config = jsonBuffer.createObject(); _haSendMagnitude(i, config); - output += "sensor:\n"; + output += "\nsensor:\n"; bool first = true; for (auto kv : config) { if (first) { @@ -197,7 +196,9 @@ String _haGetConfig() { } else { output += " "; } - output += kv.key + String(": ") + kv.value.as() + String("\n"); + String value = kv.value.as(); + value.replace("%", "'%'"); + output += kv.key + String(": ") + value + String("\n"); } output += "\n"; @@ -265,10 +266,12 @@ void _haWebSocketOnAction(uint32_t client_id, const char * action, JsonObject& d #if TERMINAL_SUPPORT void _haInitCommands() { + settingsRegisterCommand(F("HA.CONFIG"), [](Embedis* e) { DEBUG_MSG(_haGetConfig().c_str()); DEBUG_MSG_P(PSTR("+OK\n")); }); + settingsRegisterCommand(F("HA.SEND"), [](Embedis* e) { setSetting("haEnabled", "1"); _haConfigure(); @@ -277,6 +280,7 @@ void _haInitCommands() { #endif DEBUG_MSG_P(PSTR("+OK\n")); }); + settingsRegisterCommand(F("HA.CLEAR"), [](Embedis* e) { setSetting("haEnabled", "0"); _haConfigure(); @@ -285,6 +289,7 @@ void _haInitCommands() { #endif DEBUG_MSG_P(PSTR("+OK\n")); }); + } #endif