mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 08:49:52 +03:00
web and shell printing share common functions - refactor how device values are printed to shell #632
This commit is contained in:
@@ -140,7 +140,6 @@ class EMSdevice {
|
||||
void register_mqtt_cmd(const __FlashStringHelper * cmd, cmdfunction_p f);
|
||||
|
||||
// virtual functions overrules by derived classes
|
||||
virtual void show_values(uuid::console::Shell & shell) = 0;
|
||||
virtual void publish_values(JsonObject & json, bool force = false) = 0;
|
||||
virtual bool export_values(JsonObject & json) = 0;
|
||||
virtual bool updated_values() = 0;
|
||||
@@ -156,57 +155,12 @@ class EMSdevice {
|
||||
telegram_functions_.reserve(n);
|
||||
}
|
||||
|
||||
static void print_value_json(uuid::console::Shell & shell,
|
||||
const __FlashStringHelper * key,
|
||||
const __FlashStringHelper * prefix,
|
||||
const __FlashStringHelper * name,
|
||||
const __FlashStringHelper * suffix,
|
||||
JsonObject & json);
|
||||
|
||||
static void print_value_json(JsonArray & root,
|
||||
const __FlashStringHelper * key,
|
||||
const __FlashStringHelper * prefix,
|
||||
const __FlashStringHelper * name,
|
||||
const __FlashStringHelper * suffix,
|
||||
JsonObject & json);
|
||||
|
||||
// prints an EMS device value to the console, handling the correct rendering of the type
|
||||
// padding is # white space
|
||||
// name is the name of the parameter
|
||||
// suffix is any string to be appended after the value
|
||||
// format:
|
||||
// for ints its 0=no division, 255=handle as boolean, other divide by the value given and render with a decimal point
|
||||
// for floats its the precision in number of decimal places from 0 to 8
|
||||
// for bools its EMS_VALUE_BOOL (0xFF)
|
||||
template <typename Value>
|
||||
static void print_value(uuid::console::Shell & shell,
|
||||
uint8_t padding,
|
||||
const __FlashStringHelper * name,
|
||||
Value & value,
|
||||
const __FlashStringHelper * suffix,
|
||||
const uint8_t format = 0) {
|
||||
char buffer[15];
|
||||
if (Helpers::render_value(buffer, value, format) == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t i = padding;
|
||||
while (i-- > 0) {
|
||||
shell.print(F_(1space));
|
||||
}
|
||||
|
||||
shell.printf(PSTR("%s: %s"), uuid::read_flash_string(name).c_str(), buffer);
|
||||
|
||||
if (suffix != nullptr) {
|
||||
shell.print(F_(1space));
|
||||
shell.println(uuid::read_flash_string(suffix).c_str());
|
||||
} else {
|
||||
shell.println();
|
||||
}
|
||||
}
|
||||
|
||||
static void print_value(uuid::console::Shell & shell, uint8_t padding, const __FlashStringHelper * name, const __FlashStringHelper * value);
|
||||
static void print_value(uuid::console::Shell & shell, uint8_t padding, const __FlashStringHelper * name, const char * value);
|
||||
static void create_value_json(JsonArray & root,
|
||||
const __FlashStringHelper * key,
|
||||
const __FlashStringHelper * prefix,
|
||||
const __FlashStringHelper * name,
|
||||
const __FlashStringHelper * suffix,
|
||||
JsonObject & json);
|
||||
|
||||
enum Brand : uint8_t {
|
||||
NO_BRAND = 0, // 0
|
||||
|
||||
Reference in New Issue
Block a user