diff --git a/CHANGELOG.md b/CHANGELOG.md index 4871dc308..5d6c5e826 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ## [14.6.0.1] ### Added - Command `JsonPP 0..7` to enable (>0) JSON Pretty Print on user interfaces and set number of indents +- Command `JsonPP |backlog ;...` to enable JSON PP only once ### Breaking Changed diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 33a8af929..86b3063f0 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -117,6 +117,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm ## Changelog v14.6.0.1 ### Added - Command `JsonPP 0..7` to enable (>0) JSON Pretty Print on user interfaces and set number of indents +- Command `JsonPP |backlog ;...` to enable JSON PP only once ### Breaking Changed diff --git a/tasmota/tasmota_support/support_command.ino b/tasmota/tasmota_support/support_command.ino index 1bb925120..c5e33d5d0 100644 --- a/tasmota/tasmota_support/support_command.ino +++ b/tasmota/tasmota_support/support_command.ino @@ -664,6 +664,35 @@ void CmndDelay(void) { ResponseCmndNumber(bl_delay); } +void CmndJsonPP(void) { + // JsonPP 0 - Disable JSON Pretty Print + // JsonPP 1..7 - Enable JSON Pretty Print with 1..7 indent spaces + // JsonPP - If not enabled, enable JSON PP with 1 indent, execute command and restore JsonPP + // JsonPP Backlog ;... - If not enabled, enable JSON PP with 1 indent, execute command and restore JsonPP + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 7)) { + Settings->mbflag2.json_pretty_print = XdrvMailbox.payload; + } + else if (XdrvMailbox.data_len) { + uint32_t last_json_pretty_print = Settings->mbflag2.json_pretty_print; + if (0 == Settings->mbflag2.json_pretty_print) { + Settings->mbflag2.json_pretty_print = 1; // Default 1 indent if not set + } + bool backlog = (strchr(XdrvMailbox.data, ';') != nullptr); + String cmnds = XdrvMailbox.data; + if (!last_json_pretty_print && backlog) { + cmnds += ";_JsonPP "; + cmnds += last_json_pretty_print; // Restore JsonPP after execution of backlog commands + } + ExecuteCommand((char*)cmnds.c_str(), SRC_IGNORE); + if (!last_json_pretty_print && !backlog) { // Restore JsonPP after execution of single command + Settings->mbflag2.json_pretty_print = last_json_pretty_print; + } + ResponseClear(); + return; + } + ResponseCmndNumber(Settings->mbflag2.json_pretty_print); +} + void CmndPower(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.devices_present)) { @@ -1267,13 +1296,6 @@ void CmndOtaUrl(void) ResponseCmndChar(SettingsText(SET_OTAURL)); } -void CmndJsonPP(void) { - if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 7)) { - Settings->mbflag2.json_pretty_print = XdrvMailbox.payload; - } - ResponseCmndNumber(Settings->mbflag2.json_pretty_print); -} - void CmndSeriallog(void) { if ((XdrvMailbox.payload >= LOG_LEVEL_NONE) && (XdrvMailbox.payload <= LOG_LEVEL_DEBUG_MORE)) {