Browse Source

Single quote % units only in ha.config (#1227)

ota
Xose Pérez 6 years ago
parent
commit
acf68ac5c8
1 changed files with 9 additions and 4 deletions
  1. +9
    -4
      code/espurna/homeassistant.ino

+ 9
- 4
code/espurna/homeassistant.ino View File

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


Loading…
Cancel
Save