diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 69cce714e..bbc47e4da 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -383,4 +383,36 @@ void EMSdevice::print_value(uuid::console::Shell & shell, uint8_t padding, const shell.printfln(PSTR("%s: %s"), uuid::read_flash_string(name).c_str(), value); } +// print value to shell from the json doc +void EMSdevice::print_value_json(uuid::console::Shell & shell, + const __FlashStringHelper * key, + const __FlashStringHelper * name, + const __FlashStringHelper * suffix, + JsonObject & json) { + JsonVariant data = json[uuid::read_flash_string(key)]; + if (data == nullptr) { + return; // doesn't exist + } + + shell.printf(PSTR(" %s: "), uuid::read_flash_string(name).c_str()); + + if (data.is()) { + shell.printf(PSTR("%s"), data.as()); + } else if (data.is()) { + shell.printf(PSTR("%d"), data.as()); + } else if (data.is()) { + char data_str[10]; + shell.printf(PSTR("%s"), Helpers::render_value(data_str, (float)data.as(), 1)); + } else if (data.is()) { + char data_str[10]; + shell.printf(PSTR("%s"), Helpers::render_boolean(data_str, data.as())); + } + + if (suffix != nullptr) { + shell.print(uuid::read_flash_string(suffix).c_str()); + } + + shell.println(); +} + } // namespace emsesp