From 19eb755157d116091e0b8ebb3e8f49b987b3b37b Mon Sep 17 00:00:00 2001 From: Proddy Date: Fri, 5 Jan 2024 22:39:35 +0100 Subject: [PATCH] fix Arduino 7 (using to<> and not as<> --- src/emsdevice.cpp | 8 ++++++-- src/emsesp.cpp | 6 +++--- src/system.cpp | 30 +++++++++++++++--------------- src/web/WebAPIService.cpp | 2 +- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 261609b08..1cbb4a66c 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -854,7 +854,7 @@ bool EMSdevice::export_values(uint8_t device_type, JsonObject & output, const in for (const auto & emsdevice : EMSESP::emsdevices) { if (emsdevice && (emsdevice->device_type() == device_type)) { if (!nest_created && emsdevice->has_tags(tag)) { - output_hc = output[EMSdevice::tag_to_mqtt(tag)].add(); + output_hc = output[EMSdevice::tag_to_mqtt(tag)].to(); nest_created = true; } has_value |= emsdevice->generate_values(output_hc, tag, true, output_target); // use nested for id -1 and 0 @@ -1614,15 +1614,19 @@ bool EMSdevice::generate_values(JsonObject & output, const uint8_t tag_filter, c if (dv.tag != old_tag) { old_tag = dv.tag; if (nested && have_tag && dv.tag >= DeviceValueTAG::TAG_HC1) { - json = output[tag_to_mqtt(dv.tag)].add(); + json = output[tag_to_mqtt(dv.tag)].to(); } } } + // do not overwrite if (json.containsKey(name)) { +#ifdef EMSESP_DEBUG EMSESP::logger().debug("double json key: %s", name); +#endif continue; } + // handle Booleans if (dv.type == DeviceValueType::BOOL && Helpers::hasValue(*(uint8_t *)(dv.value_p), EMS_VALUE_BOOL)) { // see how to render the value depending on the setting diff --git a/src/emsesp.cpp b/src/emsesp.cpp index cc289e4df..c998770d6 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -560,15 +560,15 @@ void EMSESP::publish_device_values(uint8_t device_type) { // group by device type for (uint8_t tag = DeviceValueTAG::TAG_BOILER_DATA_WW; tag <= DeviceValueTAG::TAG_HS16; tag++) { - JsonObject json_hc = json; + JsonObject json_tag = json; bool nest_created = false; for (const auto & emsdevice : emsdevices) { if (emsdevice && (emsdevice->device_type() == device_type)) { if (nested && !nest_created && emsdevice->has_tags(tag)) { - json_hc = doc[EMSdevice::tag_to_mqtt(tag)].add(); + json_tag = doc[EMSdevice::tag_to_mqtt(tag)].to(); nest_created = true; } - need_publish |= emsdevice->generate_values(json_hc, tag, false, EMSdevice::OUTPUT_TARGET::MQTT); + need_publish |= emsdevice->generate_values(json_tag, tag, false, EMSdevice::OUTPUT_TARGET::MQTT); } } if (need_publish && ((!nested && tag >= DeviceValueTAG::TAG_DEVICE_DATA_WW) || (tag == DeviceValueTAG::TAG_BOILER_DATA_WW))) { diff --git a/src/system.cpp b/src/system.cpp index 6ba42a6b2..23813e39b 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -115,18 +115,18 @@ bool System::command_allvalues(const char * value, const int8_t id, JsonObject & for (const auto & emsdevice : EMSESP::emsdevices) { std::string title = emsdevice->device_type_2_device_name_translated() + std::string(" ") + emsdevice->to_string(); - device_output = output[title].add(); + device_output = output[title].to(); emsdevice->generate_values(device_output, DeviceValueTAG::TAG_NONE, true, EMSdevice::OUTPUT_TARGET::API_VERBOSE); // use nested for id -1 and 0 } // Custom entities - device_output = output["Custom Entities"].add(); + device_output = output["Custom Entities"].to(); EMSESP::webCustomEntityService.get_value_info(device_output, ""); // Sensors - device_output = output["Analog Sensors"].add(); + device_output = output["Analog Sensors"].to(); EMSESP::analogsensor_.command_info(nullptr, 0, device_output); - device_output = output["Temperature Sensors"].add(); + device_output = output["Temperature Sensors"].to(); EMSESP::temperaturesensor_.command_info(nullptr, 0, device_output); return true; @@ -1178,7 +1178,7 @@ void System::extractSettings(const char * filename, const char * section, JsonOb DeserializationError error = deserializeJson(jsonDocument, settingsFile); if (error == DeserializationError::Ok && jsonDocument.is()) { JsonObject jsonObject = jsonDocument.as(); - JsonObject node = output[section].add(); + JsonObject node = output[section].to(); for (JsonPair kvp : jsonObject) { node[kvp.key()] = kvp.value(); } @@ -1211,7 +1211,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp JsonObject node; // System - node = output["System Info"].add(); + node = output["System Info"].to(); node["version"] = EMSESP_APP_VERSION; node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3); node["uptime (seconds)"] = uuid::get_uptime_sec(); @@ -1228,7 +1228,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp #ifndef EMSESP_STANDALONE // Network Status - node = output["Network Info"].add(); + node = output["Network Info"].to(); if (EMSESP::system_.ethernet_connected()) { node["network"] = "Ethernet"; node["hostname"] = ETH.getHostname(); @@ -1276,7 +1276,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp #endif // NTP status - node = output["NTP Info"].add(); + node = output["NTP Info"].to(); #ifndef EMSESP_STANDALONE node["NTP status"] = EMSESP::system_.ntp_connected() ? "connected" : "disconnected"; EMSESP::esp8266React.getNTPSettingsService()->read([&](NTPSettings & settings) { @@ -1287,7 +1287,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp }); // OTA status - node = output["OTA Info"].add(); + node = output["OTA Info"].to(); EMSESP::esp8266React.getOTASettingsService()->read([&](OTASettings & settings) { node["enabled"] = settings.enabled; node["port"] = settings.port; @@ -1295,7 +1295,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp #endif // MQTT Status - node = output["MQTT Info"].add(); + node = output["MQTT Info"].to(); node["MQTT status"] = Mqtt::connected() ? F_(connected) : F_(disconnected); if (Mqtt::enabled()) { node["MQTT publishes"] = Mqtt::publish_count(); @@ -1329,7 +1329,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp }); // Syslog Status - node = output["Syslog Info"].add(); + node = output["Syslog Info"].to(); node["enabled"] = EMSESP::system_.syslog_enabled_; #ifndef EMSESP_STANDALONE if (EMSESP::system_.syslog_enabled_) { @@ -1341,7 +1341,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp #endif // Sensor Status - node = output["Sensor Info"].add(); + node = output["Sensor Info"].to(); if (EMSESP::sensor_enabled()) { node["temperature sensors"] = EMSESP::temperaturesensor_.no_sensors(); node["temperature sensor reads"] = EMSESP::temperaturesensor_.reads(); @@ -1354,12 +1354,12 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp } // API Status - node = output["API Info"].add(); + node = output["API Info"].to(); node["API calls"] = WebAPIService::api_count(); node["API fails"] = WebAPIService::api_fails(); // EMS Bus Status - node = output["Bus Info"].add(); + node = output["Bus Info"].to(); switch (EMSESP::bus_status()) { case EMSESP::BUS_STATUS_OFFLINE: node["bus status"] = "disconnected"; @@ -1387,7 +1387,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp } // Settings - node = output["Settings"].add(); + node = output["Settings"].to(); EMSESP::webSettingsService.read([&](WebSettings & settings) { node["board profile"] = settings.board_profile; node["locale"] = settings.locale; diff --git a/src/web/WebAPIService.cpp b/src/web/WebAPIService.cpp index 969f72f94..1de7230b5 100644 --- a/src/web/WebAPIService.cpp +++ b/src/web/WebAPIService.cpp @@ -168,7 +168,7 @@ void WebAPIService::getSettings(AsyncWebServerRequest * request) { root["type"] = "settings"; - JsonObject node = root["System"].add(); + JsonObject node = root["System"].to(); node["version"] = EMSESP_APP_VERSION; System::extractSettings(NETWORK_SETTINGS_FILE, "Network", root);