fix for showing on/off in console

This commit is contained in:
proddy
2021-02-27 15:52:25 +01:00
parent 39b8a2b559
commit 95563c7d69
2 changed files with 7 additions and 3 deletions

View File

@@ -538,6 +538,7 @@ bool EMSdevice::generate_values_json_web(JsonObject & json) {
// For each value in the device create the json object pair and add it to given json // For each value in the device create the json object pair and add it to given json
// return false if empty // return false if empty
// this is used to create both the MQTT payloads and Console messages
bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter, const bool verbose) { bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter, const bool verbose) {
bool has_value = false; // to see if we've added a value. it's faster than doing a json.size() at the end bool has_value = false; // to see if we've added a value. it's faster than doing a json.size() at the end
uint8_t old_tag = 255; uint8_t old_tag = 255;
@@ -573,7 +574,8 @@ bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter
has_value = true; has_value = true;
} else { } else {
// see how to render the value depending on the setting // see how to render the value depending on the setting
if (Mqtt::bool_format() == BOOL_FORMAT_ONOFF) { // when in verbose mode (i.e. outout is Console) we always use on and off
if ((Mqtt::bool_format() == BOOL_FORMAT_ONOFF) || verbose) {
// on or off as strings // on or off as strings
json[name] = *(uint8_t *)(dv.value_p) ? F_(on) : F_(off); json[name] = *(uint8_t *)(dv.value_p) ? F_(on) : F_(off);
has_value = true; has_value = true;

View File

@@ -274,6 +274,7 @@ void EMSESP::show_ems(uuid::console::Shell & shell) {
} }
// show EMS device values to the shell console // show EMS device values to the shell console
// this is the only time generate_values_json is called in verbose mode (set to true)
void EMSESP::show_device_values(uuid::console::Shell & shell) { void EMSESP::show_device_values(uuid::console::Shell & shell) {
if (emsdevices.empty()) { if (emsdevices.empty()) {
shell.printfln(F("No EMS devices detected. Try using 'scan devices' from the ems menu.")); shell.printfln(F("No EMS devices detected. Try using 'scan devices' from the ems menu."));
@@ -415,6 +416,7 @@ void EMSESP::reset_mqtt_ha() {
} }
// create json doc for the devices values and add to MQTT publish queue // create json doc for the devices values and add to MQTT publish queue
// generate_values_json is called without verbose mode (defaults to false)
void EMSESP::publish_device_values(uint8_t device_type) { void EMSESP::publish_device_values(uint8_t device_type) {
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE_DYN); // use max size DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE_DYN); // use max size
JsonObject json = doc.to<JsonObject>(); JsonObject json = doc.to<JsonObject>();
@@ -441,7 +443,7 @@ void EMSESP::publish_device_values(uint8_t device_type) {
} }
if ((device_type != DeviceType::THERMOSTAT) || (emsdevice->device_id() == EMSESP::actual_master_thermostat())) { if ((device_type != DeviceType::THERMOSTAT) || (emsdevice->device_id() == EMSESP::actual_master_thermostat())) {
// for all other devices add the values to the json, without verbose mode // for all other devices add the values to the json
has_value |= emsdevice->generate_values_json(json, DeviceValueTAG::TAG_NONE); has_value |= emsdevice->generate_values_json(json, DeviceValueTAG::TAG_NONE);
} }
} }
@@ -879,7 +881,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, std::
} }
// export all values to info command // export all values to info command
// value and id are ignored // value is ignored here
bool EMSESP::command_info(uint8_t device_type, JsonObject & json, const int8_t id) { bool EMSESP::command_info(uint8_t device_type, JsonObject & json, const int8_t id) {
bool has_value = false; bool has_value = false;
uint8_t tag = DeviceValueTAG::TAG_NONE; uint8_t tag = DeviceValueTAG::TAG_NONE;