From 10d6728c821005f6963a5e0817e90a710e6ab62f Mon Sep 17 00:00:00 2001 From: Proddy Date: Sat, 6 Jan 2024 17:42:42 +0100 Subject: [PATCH] remove obsolete reference to JsonObject --- lib/framework/APSettingsService.h | 4 +-- lib/framework/ArduinoJsonJWT.cpp | 2 +- lib/framework/ArduinoJsonJWT.h | 2 +- lib/framework/JsonUtils.h | 6 ++-- lib/framework/MqttSettingsService.cpp | 4 +-- lib/framework/MqttSettingsService.h | 4 +-- lib/framework/NTPSettingsService.h | 4 +-- lib/framework/NetworkSettingsService.h | 4 +-- lib/framework/OTASettingsService.h | 4 +-- lib/framework/SecuritySettingsService.cpp | 4 +-- lib/framework/SecuritySettingsService.h | 6 ++-- lib/framework/StatefulService.h | 10 +++--- lib_standalone/ESP8266React.h | 6 ++-- lib_standalone/SecuritySettingsService.cpp | 4 +-- lib_standalone/SecuritySettingsService.h | 6 ++-- lib_standalone/StatefulService.h | 10 +++--- src/analogsensor.cpp | 12 +++---- src/analogsensor.h | 6 ++-- src/command.cpp | 6 ++-- src/command.h | 10 +++--- src/emsdevice.cpp | 10 +++--- src/emsdevice.h | 12 +++---- src/emsesp.cpp | 14 ++++---- src/emsesp.h | 6 ++-- src/mqtt.cpp | 40 +++++++++++----------- src/mqtt.h | 40 +++++++++++----------- src/shower.cpp | 2 +- src/system.cpp | 14 ++++---- src/system.h | 14 ++++---- src/temperaturesensor.cpp | 12 +++---- src/temperaturesensor.h | 6 ++-- src/web/WebAPIService.cpp | 2 +- src/web/WebAPIService.h | 2 +- src/web/WebCustomEntityService.cpp | 12 +++---- src/web/WebCustomEntityService.h | 12 +++---- src/web/WebCustomizationService.cpp | 4 +-- src/web/WebCustomizationService.h | 4 +-- src/web/WebSchedulerService.cpp | 6 ++-- src/web/WebSchedulerService.h | 6 ++-- src/web/WebSettingsService.cpp | 4 +-- src/web/WebSettingsService.h | 4 +-- 41 files changed, 170 insertions(+), 170 deletions(-) diff --git a/lib/framework/APSettingsService.h b/lib/framework/APSettingsService.h index 68bca2135..c2eacd084 100644 --- a/lib/framework/APSettingsService.h +++ b/lib/framework/APSettingsService.h @@ -75,7 +75,7 @@ class APSettings { && subnetMask == settings.subnetMask; } - static void read(APSettings & settings, JsonObject & root) { + static void read(APSettings & settings, JsonObject root) { root["provision_mode"] = settings.provisionMode; root["ssid"] = settings.ssid; root["password"] = settings.password; @@ -87,7 +87,7 @@ class APSettings { root["subnet_mask"] = settings.subnetMask.toString(); } - static StateUpdateResult update(JsonObject & root, APSettings & settings) { + static StateUpdateResult update(JsonObject root, APSettings & settings) { APSettings newSettings = {}; newSettings.provisionMode = root["provision_mode"] | FACTORY_AP_PROVISION_MODE; switch (settings.provisionMode) { diff --git a/lib/framework/ArduinoJsonJWT.cpp b/lib/framework/ArduinoJsonJWT.cpp index adca88f3e..595166ec5 100644 --- a/lib/framework/ArduinoJsonJWT.cpp +++ b/lib/framework/ArduinoJsonJWT.cpp @@ -34,7 +34,7 @@ String ArduinoJsonJWT::sign(String & payload) { return encode((char *)hmacResult, 32); } -String ArduinoJsonJWT::buildJWT(JsonObject & payload) { +String ArduinoJsonJWT::buildJWT(JsonObject payload) { // serialize, then encode payload String jwt; serializeJson(payload, jwt); diff --git a/lib/framework/ArduinoJsonJWT.h b/lib/framework/ArduinoJsonJWT.h index 3a76f71f6..cd13d5fa4 100644 --- a/lib/framework/ArduinoJsonJWT.h +++ b/lib/framework/ArduinoJsonJWT.h @@ -25,7 +25,7 @@ class ArduinoJsonJWT { void setSecret(String secret); String getSecret(); - String buildJWT(JsonObject & payload); + String buildJWT(JsonObject payload); void parseJWT(String jwt, JsonDocument & jsonDocument); }; diff --git a/lib/framework/JsonUtils.h b/lib/framework/JsonUtils.h index 3fa38cb12..29a72bd6a 100644 --- a/lib/framework/JsonUtils.h +++ b/lib/framework/JsonUtils.h @@ -8,19 +8,19 @@ class JsonUtils { public: - static void readIP(JsonObject & root, const String & key, IPAddress & ip, const String & def) { + static void readIP(JsonObject root, const String & key, IPAddress & ip, const String & def) { IPAddress defaultIp = {}; if (!defaultIp.fromString(def)) { defaultIp = INADDR_NONE; } readIP(root, key, ip, defaultIp); } - static void readIP(JsonObject & root, const String & key, IPAddress & ip, const IPAddress & defaultIp = INADDR_NONE) { + static void readIP(JsonObject root, const String & key, IPAddress & ip, const IPAddress & defaultIp = INADDR_NONE) { if (!root[key].is() || !ip.fromString(root[key].as())) { ip = defaultIp; } } - static void writeIP(JsonObject & root, const String & key, const IPAddress & ip) { + static void writeIP(JsonObject root, const String & key, const IPAddress & ip) { if (IPUtils::isSet(ip)) { root[key] = ip.toString(); } diff --git a/lib/framework/MqttSettingsService.cpp b/lib/framework/MqttSettingsService.cpp index 4465963a4..5c28d88a3 100644 --- a/lib/framework/MqttSettingsService.cpp +++ b/lib/framework/MqttSettingsService.cpp @@ -216,7 +216,7 @@ bool MqttSettingsService::configureMqtt() { return false; } -void MqttSettings::read(MqttSettings & settings, JsonObject & root) { +void MqttSettings::read(MqttSettings & settings, JsonObject root) { #if CONFIG_IDF_TARGET_ESP32S3 #ifndef TASMOTA_SDK root["enableTLS"] = settings.enableTLS; @@ -252,7 +252,7 @@ void MqttSettings::read(MqttSettings & settings, JsonObject & root) { root["send_response"] = settings.send_response; } -StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & settings) { +StateUpdateResult MqttSettings::update(JsonObject root, MqttSettings & settings) { MqttSettings newSettings = {}; bool changed = false; diff --git a/lib/framework/MqttSettingsService.h b/lib/framework/MqttSettingsService.h index e2541dcda..93bd0d163 100644 --- a/lib/framework/MqttSettingsService.h +++ b/lib/framework/MqttSettingsService.h @@ -97,8 +97,8 @@ class MqttSettings { bool send_response; uint8_t entity_format; - static void read(MqttSettings & settings, JsonObject & root); - static StateUpdateResult update(JsonObject & root, MqttSettings & settings); + static void read(MqttSettings & settings, JsonObject root); + static StateUpdateResult update(JsonObject root, MqttSettings & settings); }; class MqttSettingsService : public StatefulService { diff --git a/lib/framework/NTPSettingsService.h b/lib/framework/NTPSettingsService.h index f26273ecf..ab00b36d7 100644 --- a/lib/framework/NTPSettingsService.h +++ b/lib/framework/NTPSettingsService.h @@ -36,14 +36,14 @@ class NTPSettings { String tzFormat; String server; - static void read(NTPSettings & settings, JsonObject & root) { + static void read(NTPSettings & settings, JsonObject root) { root["enabled"] = settings.enabled; root["server"] = settings.server; root["tz_label"] = settings.tzLabel; root["tz_format"] = settings.tzFormat; } - static StateUpdateResult update(JsonObject & root, NTPSettings & settings) { + static StateUpdateResult update(JsonObject root, NTPSettings & settings) { settings.enabled = root["enabled"] | FACTORY_NTP_ENABLED; settings.server = root["server"] | FACTORY_NTP_SERVER; settings.tzLabel = root["tz_label"] | FACTORY_NTP_TIME_ZONE_LABEL; diff --git a/lib/framework/NetworkSettingsService.h b/lib/framework/NetworkSettingsService.h index 901345ea9..96a9b116c 100644 --- a/lib/framework/NetworkSettingsService.h +++ b/lib/framework/NetworkSettingsService.h @@ -50,7 +50,7 @@ class NetworkSettings { IPAddress dnsIP1; IPAddress dnsIP2; - static void read(NetworkSettings & settings, JsonObject & root) { + static void read(NetworkSettings & settings, JsonObject root) { // connection settings root["ssid"] = settings.ssid; root["bssid"] = settings.bssid; @@ -73,7 +73,7 @@ class NetworkSettings { JsonUtils::writeIP(root, "dns_ip_2", settings.dnsIP2); } - static StateUpdateResult update(JsonObject & root, NetworkSettings & settings) { + static StateUpdateResult update(JsonObject root, NetworkSettings & settings) { auto enableCORS = settings.enableCORS; auto CORSOrigin = settings.CORSOrigin; auto ssid = settings.ssid; diff --git a/lib/framework/OTASettingsService.h b/lib/framework/OTASettingsService.h index 2594f98db..12818c07e 100644 --- a/lib/framework/OTASettingsService.h +++ b/lib/framework/OTASettingsService.h @@ -28,13 +28,13 @@ class OTASettings { int port; String password; - static void read(OTASettings & settings, JsonObject & root) { + static void read(OTASettings & settings, JsonObject root) { root["enabled"] = settings.enabled; root["port"] = settings.port; root["password"] = settings.password; } - static StateUpdateResult update(JsonObject & root, OTASettings & settings) { + static StateUpdateResult update(JsonObject root, OTASettings & settings) { settings.enabled = root["enabled"] | FACTORY_OTA_ENABLED; settings.port = root["port"] | FACTORY_OTA_PORT; settings.password = root["password"] | FACTORY_OTA_PASSWORD; diff --git a/lib/framework/SecuritySettingsService.cpp b/lib/framework/SecuritySettingsService.cpp index caab87419..f17f5f4f1 100644 --- a/lib/framework/SecuritySettingsService.cpp +++ b/lib/framework/SecuritySettingsService.cpp @@ -63,12 +63,12 @@ Authentication SecuritySettingsService::authenticate(const String & username, co return Authentication(); } -inline void populateJWTPayload(JsonObject & payload, User * user) { +inline void populateJWTPayload(JsonObject payload, User * user) { payload["username"] = user->username; payload["admin"] = user->admin; } -boolean SecuritySettingsService::validatePayload(JsonObject & parsedPayload, User * user) { +boolean SecuritySettingsService::validatePayload(JsonObject parsedPayload, User * user) { JsonDocument jsonDocument; JsonObject payload = jsonDocument.to(); populateJWTPayload(payload, user); diff --git a/lib/framework/SecuritySettingsService.h b/lib/framework/SecuritySettingsService.h index e429e049b..7010ae99c 100644 --- a/lib/framework/SecuritySettingsService.h +++ b/lib/framework/SecuritySettingsService.h @@ -35,7 +35,7 @@ class SecuritySettings { String jwtSecret; std::list users; - static void read(SecuritySettings & settings, JsonObject & root) { + static void read(SecuritySettings & settings, JsonObject root) { // secret root["jwt_secret"] = settings.jwtSecret; @@ -49,7 +49,7 @@ class SecuritySettings { } } - static StateUpdateResult update(JsonObject & root, SecuritySettings & settings) { + static StateUpdateResult update(JsonObject root, SecuritySettings & settings) { // secret settings.jwtSecret = root["jwt_secret"] | FACTORY_JWT_SECRET; @@ -98,7 +98,7 @@ class SecuritySettingsService : public StatefulService, public /* * Verify the payload is correct */ - boolean validatePayload(JsonObject & parsedPayload, User * user); + boolean validatePayload(JsonObject parsedPayload, User * user); }; #else diff --git a/lib/framework/StatefulService.h b/lib/framework/StatefulService.h index f464cad29..f6510cf25 100644 --- a/lib/framework/StatefulService.h +++ b/lib/framework/StatefulService.h @@ -17,10 +17,10 @@ enum class StateUpdateResult { }; template -using JsonStateUpdater = std::function; +using JsonStateUpdater = std::function; template -using JsonStateReader = std::function; +using JsonStateReader = std::function; typedef size_t update_handler_id_t; typedef std::function StateUpdateCallback; @@ -81,7 +81,7 @@ class StatefulService { return result; } - StateUpdateResult update(JsonObject & jsonObject, JsonStateUpdater stateUpdater, const String & originId) { + StateUpdateResult update(JsonObject jsonObject, JsonStateUpdater stateUpdater, const String & originId) { beginTransaction(); StateUpdateResult result = stateUpdater(jsonObject, _state); endTransaction(); @@ -91,7 +91,7 @@ class StatefulService { return result; } - StateUpdateResult updateWithoutPropagation(JsonObject & jsonObject, JsonStateUpdater stateUpdater) { + StateUpdateResult updateWithoutPropagation(JsonObject jsonObject, JsonStateUpdater stateUpdater) { beginTransaction(); StateUpdateResult result = stateUpdater(jsonObject, _state); endTransaction(); @@ -104,7 +104,7 @@ class StatefulService { endTransaction(); } - void read(JsonObject & jsonObject, JsonStateReader stateReader) { + void read(JsonObject jsonObject, JsonStateReader stateReader) { beginTransaction(); stateReader(_state, jsonObject); endTransaction(); diff --git a/lib_standalone/ESP8266React.h b/lib_standalone/ESP8266React.h index b19417273..68174ea61 100644 --- a/lib_standalone/ESP8266React.h +++ b/lib_standalone/ESP8266React.h @@ -75,10 +75,10 @@ class DummySettings { bool enableCORS = false; String CORSOrigin = "*"; - static void read(DummySettings & settings, JsonObject & root){}; + static void read(DummySettings & settings, JsonObject root){}; static void read(DummySettings & settings){}; - static StateUpdateResult update(JsonObject & root, DummySettings & settings) { + static StateUpdateResult update(JsonObject root, DummySettings & settings) { return StateUpdateResult::CHANGED; } }; @@ -152,7 +152,7 @@ class EMSESPSettingsService { class JsonUtils { public: - static void writeIP(JsonObject & root, const String & key, const String & ip) { + static void writeIP(JsonObject root, const String & key, const String & ip) { root[key] = ip; } }; diff --git a/lib_standalone/SecuritySettingsService.cpp b/lib_standalone/SecuritySettingsService.cpp index d90e73a34..dc5f3860c 100644 --- a/lib_standalone/SecuritySettingsService.cpp +++ b/lib_standalone/SecuritySettingsService.cpp @@ -62,12 +62,12 @@ Authentication SecuritySettingsService::authenticate(const String & username, co return Authentication(); } -inline void populateJWTPayload(JsonObject & payload, User * user) { +inline void populateJWTPayload(JsonObject payload, User * user) { payload["username"] = user->username; payload["admin"] = user->admin; } -boolean SecuritySettingsService::validatePayload(JsonObject & parsedPayload, User * user) { +boolean SecuritySettingsService::validatePayload(JsonObject parsedPayload, User * user) { JsonDocument jsonDocument; JsonObject payload = jsonDocument.to(); populateJWTPayload(payload, user); diff --git a/lib_standalone/SecuritySettingsService.h b/lib_standalone/SecuritySettingsService.h index 25e27667e..a283854e0 100644 --- a/lib_standalone/SecuritySettingsService.h +++ b/lib_standalone/SecuritySettingsService.h @@ -32,7 +32,7 @@ class SecuritySettings { String jwtSecret; std::list users; - static void read(SecuritySettings & settings, JsonObject & root) { + static void read(SecuritySettings & settings, JsonObject root) { // secret root["jwt_secret"] = settings.jwtSecret; @@ -46,7 +46,7 @@ class SecuritySettings { } } - static StateUpdateResult update(JsonObject & root, SecuritySettings & settings) { + static StateUpdateResult update(JsonObject root, SecuritySettings & settings) { // secret settings.jwtSecret = root["jwt_secret"] | FACTORY_JWT_SECRET; @@ -85,7 +85,7 @@ class SecuritySettingsService : public StatefulService, public void configureJWTHandler(); Authentication authenticateJWT(String & jwt); - boolean validatePayload(JsonObject & parsedPayload, User * user); + boolean validatePayload(JsonObject parsedPayload, User * user); }; #else diff --git a/lib_standalone/StatefulService.h b/lib_standalone/StatefulService.h index fa29e26c0..577b51fbb 100644 --- a/lib_standalone/StatefulService.h +++ b/lib_standalone/StatefulService.h @@ -15,10 +15,10 @@ enum class StateUpdateResult { }; template -using JsonStateUpdater = std::function; +using JsonStateUpdater = std::function; template -using JsonStateReader = std::function; +using JsonStateReader = std::function; typedef size_t update_handler_id_t; typedef std::function StateUpdateCallback; @@ -85,7 +85,7 @@ class StatefulService { return result; } - StateUpdateResult update(JsonObject & jsonObject, JsonStateUpdater stateUpdater, const String & originId) { + StateUpdateResult update(JsonObject jsonObject, JsonStateUpdater stateUpdater, const String & originId) { beginTransaction(); StateUpdateResult result = stateUpdater(jsonObject, _state); endTransaction(); @@ -95,7 +95,7 @@ class StatefulService { return result; } - StateUpdateResult updateWithoutPropagation(JsonObject & jsonObject, JsonStateUpdater stateUpdater) { + StateUpdateResult updateWithoutPropagation(JsonObject jsonObject, JsonStateUpdater stateUpdater) { beginTransaction(); StateUpdateResult result = stateUpdater(jsonObject, _state); endTransaction(); @@ -108,7 +108,7 @@ class StatefulService { endTransaction(); } - void read(JsonObject & jsonObject, JsonStateReader stateReader) { + void read(JsonObject jsonObject, JsonStateReader stateReader) { beginTransaction(); stateReader(_state, jsonObject); endTransaction(); diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index 1396776f9..fcb051839 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -37,12 +37,12 @@ void AnalogSensor::start() { Command::add( EMSdevice::DeviceType::ANALOGSENSOR, F_(info), - [&](const char * value, const int8_t id, JsonObject & output) { return command_info(value, id, output); }, + [&](const char * value, const int8_t id, JsonObject output) { return command_info(value, id, output); }, FL_(info_cmd)); Command::add( EMSdevice::DeviceType::ANALOGSENSOR, F_(values), - [&](const char * value, const int8_t id, JsonObject & output) { return command_info(value, 0, output); }, + [&](const char * value, const int8_t id, JsonObject output) { return command_info(value, 0, output); }, nullptr, CommandFlag::HIDDEN); // this command is hidden Command::add( @@ -54,7 +54,7 @@ void AnalogSensor::start() { Command::add( EMSdevice::DeviceType::ANALOGSENSOR, F_(commands), - [&](const char * value, const int8_t id, JsonObject & output) { return command_commands(value, id, output); }, + [&](const char * value, const int8_t id, JsonObject output) { return command_commands(value, id, output); }, FL_(commands_cmd)); char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; @@ -638,7 +638,7 @@ void AnalogSensor::publish_values(const bool force) { // called from emsesp.cpp, similar to the emsdevice->get_value_info // searches by name -bool AnalogSensor::get_value_info(JsonObject & output, const char * cmd, const int8_t id) const { +bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int8_t id) const { if (sensors_.empty()) { return true; } @@ -699,7 +699,7 @@ bool AnalogSensor::get_value_info(JsonObject & output, const char * cmd, const i // creates JSON doc from values // returns true if there are no sensors -bool AnalogSensor::command_info(const char * value, const int8_t id, JsonObject & output) const { +bool AnalogSensor::command_info(const char * value, const int8_t id, JsonObject output) const { if (sensors_.empty()) { return true; } @@ -851,7 +851,7 @@ bool AnalogSensor::command_setvalue(const char * value, const int8_t gpio) { } // list commands -bool AnalogSensor::command_commands(const char * value, const int8_t id, JsonObject & output) { +bool AnalogSensor::command_commands(const char * value, const int8_t id, JsonObject output) { return Command::list(EMSdevice::DeviceType::ANALOGSENSOR, output); } diff --git a/src/analogsensor.h b/src/analogsensor.h index b33fb1137..01e353572 100644 --- a/src/analogsensor.h +++ b/src/analogsensor.h @@ -153,10 +153,10 @@ class AnalogSensor { } bool update(uint8_t gpio, const std::string & name, double offset, double factor, uint8_t uom, int8_t type, bool deleted = false); - bool get_value_info(JsonObject & output, const char * cmd, const int8_t id) const; + bool get_value_info(JsonObject output, const char * cmd, const int8_t id) const; void store_counters(); - bool command_info(const char * value, const int8_t id, JsonObject & output) const; + bool command_info(const char * value, const int8_t id, JsonObject output) const; #if defined(EMSESP_TEST) @@ -172,7 +172,7 @@ class AnalogSensor { void remove_ha_topic(const int8_t type, const uint8_t id) const; bool command_setvalue(const char * value, const int8_t gpio); void measure(); - bool command_commands(const char * value, const int8_t id, JsonObject & output); + bool command_commands(const char * value, const int8_t id, JsonObject output); std::vector sensors_; // our list of sensors diff --git a/src/command.cpp b/src/command.cpp index 284c6ae90..e59d239b8 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -30,7 +30,7 @@ std::vector Command::cmdfunctions_; // the path is leading so if duplicate keys are in the input JSON it will be ignored // the entry point will be either via the Web API (api/) or MQTT (/) // returns a return code and json output -uint8_t Command::process(const char * path, const bool is_admin, const JsonObject & input, JsonObject & output) { +uint8_t Command::process(const char * path, const bool is_admin, const JsonObject input, JsonObject output) { SUrlParser p; // parse URL for the path names p.parse(path); @@ -288,7 +288,7 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * // calls a command. Takes a json object for output. // id may be used to represent a heating circuit for example // returns 0 if the command errored, 1 (TRUE) if ok, 2 if not found, 3 if error or 4 if not allowed -uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * value, const bool is_admin, const int8_t id, JsonObject & output) { +uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * value, const bool is_admin, const int8_t id, JsonObject output) { if (cmd == nullptr) { return CommandRet::NOT_FOUND; } @@ -435,7 +435,7 @@ void Command::erase_command(const uint8_t device_type, const char * cmd) { } // list all commands for a specific device, output as json -bool Command::list(const uint8_t device_type, JsonObject & output) { +bool Command::list(const uint8_t device_type, JsonObject output) { if (cmdfunctions_.empty()) { output["message"] = "no commands available"; return false; diff --git a/src/command.h b/src/command.h index f0b54bbf2..db00fa01a 100644 --- a/src/command.h +++ b/src/command.h @@ -49,7 +49,7 @@ enum CommandRet : uint8_t { }; using cmd_function_p = std::function; -using cmd_json_function_p = std::function; +using cmd_json_function_p = std::function; class Command { public: @@ -96,7 +96,7 @@ class Command { return cmdfunctions_; } - static uint8_t call(const uint8_t device_type, const char * cmd, const char * value, const bool is_admin, const int8_t id, JsonObject & output); + static uint8_t call(const uint8_t device_type, const char * cmd, const char * value, const bool is_admin, const int8_t id, JsonObject output); static uint8_t call(const uint8_t device_type, const char * cmd, const char * value); // with normal call back function taking a value and id @@ -129,9 +129,9 @@ class Command { static void show_devices(uuid::console::Shell & shell); static bool device_has_commands(const uint8_t device_type); - static bool list(const uint8_t device_type, JsonObject & output); + static bool list(const uint8_t device_type, JsonObject output); - static uint8_t process(const char * path, const bool is_admin, const JsonObject & input, JsonObject & output); + static uint8_t process(const char * path, const bool is_admin, const JsonObject input, JsonObject output); static const char * parse_command_string(const char * command, int8_t & id); @@ -142,7 +142,7 @@ class Command { static std::vector cmdfunctions_; // the list of commands - inline static uint8_t message(uint8_t error_code, const char * message, const JsonObject & output) { + inline static uint8_t message(uint8_t error_code, const char * message, const JsonObject output) { output.clear(); output["message"] = message; return error_code; diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 1cbb4a66c..bdad16477 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -366,7 +366,7 @@ bool EMSdevice::has_cmd(const char * cmd, const int8_t id) const { // list of registered device entries // called from the command 'entities' -void EMSdevice::list_device_entries(JsonObject & output) const { +void EMSdevice::list_device_entries(JsonObject output) const { for (const auto & dv : devicevalues_) { auto fullname = dv.get_fullname(); if (!dv.has_state(DeviceValueState::DV_WEB_EXCLUDE) && dv.type != DeviceValueType::CMD && !fullname.empty()) { @@ -827,7 +827,7 @@ std::string EMSdevice::get_value_uom(const std::string & shortname) const { return std::string{}; // not found } -bool EMSdevice::export_values(uint8_t device_type, JsonObject & output, const int8_t id, const uint8_t output_target) { +bool EMSdevice::export_values(uint8_t device_type, JsonObject output, const int8_t id, const uint8_t output_target) { bool has_value = false; uint8_t tag; if (id >= 1 && id <= (1 + DeviceValueTAG::TAG_HS16 - DeviceValueTAG::TAG_HC1)) { @@ -868,7 +868,7 @@ bool EMSdevice::export_values(uint8_t device_type, JsonObject & output, const in // this is loosely based of the function generate_values used for the MQTT and Console // except additional data is stored in the JSON document needed for the Web UI like the UOM and command // v=value, u=uom, n=name, c=cmd, h=help string, s=step, m=min, x=max -void EMSdevice::generate_values_web(JsonObject & output) { +void EMSdevice::generate_values_web(JsonObject output) { // output["label"] = to_string_short(); // output["label"] = name_; JsonArray data = output["data"].to(); @@ -1362,7 +1362,7 @@ void EMSdevice::dump_value_info() { // builds json for a specific device value / entity // cmd is the endpoint or name of the device entity // returns false if failed, otherwise true -bool EMSdevice::get_value_info(JsonObject & output, const char * cmd, const int8_t id) { +bool EMSdevice::get_value_info(JsonObject output, const char * cmd, const int8_t id) { JsonObject json = output; int8_t tag = id; @@ -1568,7 +1568,7 @@ void EMSdevice::publish_all_values() { // For each value in the device create the json object pair and add it to given json // return false if empty // this is used to create the MQTT payloads, Console messages and Web API calls -bool EMSdevice::generate_values(JsonObject & output, const uint8_t tag_filter, const bool nested, const uint8_t output_target) { +bool EMSdevice::generate_values(JsonObject output, const uint8_t tag_filter, const bool nested, const uint8_t output_target) { bool has_values = 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; // NAN JsonObject json = output; diff --git a/src/emsdevice.h b/src/emsdevice.h index afd0f2aea..d1b47261f 100644 --- a/src/emsdevice.h +++ b/src/emsdevice.h @@ -51,7 +51,7 @@ class EMSdevice { static const char * uom_to_string(uint8_t uom); static const char * tag_to_mqtt(uint8_t tag); static uint8_t decode_brand(uint8_t value); - static bool export_values(uint8_t device_type, JsonObject & output, const int8_t id, const uint8_t output_target); + static bool export_values(uint8_t device_type, JsonObject output, const int8_t id, const uint8_t output_target); // non static @@ -204,7 +204,7 @@ class EMSdevice { void show_telegram_handlers(uuid::console::Shell & shell) const; char * show_telegram_handlers(char * result, const size_t len, const uint8_t handlers); void show_mqtt_handlers(uuid::console::Shell & shell) const; - void list_device_entries(JsonObject & output) const; + void list_device_entries(JsonObject output) const; void add_handlers_ignored(const uint16_t handler); void set_climate_minmax(uint8_t tag, int16_t min, uint32_t max); @@ -216,12 +216,12 @@ class EMSdevice { std::string get_value_uom(const std::string & shortname) const; - bool get_value_info(JsonObject & root, const char * cmd, const int8_t id); - void get_dv_info(JsonObject & json); + bool get_value_info(JsonObject root, const char * cmd, const int8_t id); + void get_dv_info(JsonObject json); enum OUTPUT_TARGET : uint8_t { API_VERBOSE, API_SHORTNAMES, MQTT, CONSOLE }; - bool generate_values(JsonObject & output, const uint8_t tag_filter, const bool nested, const uint8_t output_target); - void generate_values_web(JsonObject & output); + bool generate_values(JsonObject output, const uint8_t tag_filter, const bool nested, const uint8_t output_target); + void generate_values_web(JsonObject output); void generate_values_web_customization(JsonArray & output); void add_device_value(uint8_t tag, diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 8251820e4..56a609d7d 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -662,7 +662,7 @@ void EMSESP::publish_response(std::shared_ptr telegram) { // builds json with the detail of each value, // for a specific EMS device type or the sensors, scheduler and custom entities -bool EMSESP::get_device_value_info(JsonObject & root, const char * cmd, const int8_t id, const uint8_t devicetype) { +bool EMSESP::get_device_value_info(JsonObject root, const char * cmd, const int8_t id, const uint8_t devicetype) { for (const auto & emsdevice : emsdevices) { if (emsdevice->device_type() == devicetype) { if (emsdevice->get_value_info(root, cmd, id)) { @@ -1170,14 +1170,14 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const Command::add( device_type, F_(info), - [device_type](const char * value, const int8_t id, JsonObject & output) { + [device_type](const char * value, const int8_t id, JsonObject output) { return EMSdevice::export_values(device_type, output, id, EMSdevice::OUTPUT_TARGET::API_VERBOSE); }, FL_(info_cmd)); Command::add( device_type, F_(values), - [device_type](const char * value, const int8_t id, JsonObject & output) { + [device_type](const char * value, const int8_t id, JsonObject output) { return EMSdevice::export_values(device_type, output, id, @@ -1188,12 +1188,12 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const Command::add( device_type, F_(commands), - [device_type](const char * value, const int8_t id, JsonObject & output) { return command_commands(device_type, output, id); }, + [device_type](const char * value, const int8_t id, JsonObject output) { return command_commands(device_type, output, id); }, FL_(commands_cmd)); Command::add( device_type, F_(entities), - [device_type](const char * value, const int8_t id, JsonObject & output) { return command_entities(device_type, output, id); }, + [device_type](const char * value, const int8_t id, JsonObject output) { return command_entities(device_type, output, id); }, FL_(entities_cmd)); // MQTT subscribe to the device e.g. "ems-esp/boiler/#" @@ -1204,7 +1204,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const } // list device entities -bool EMSESP::command_entities(uint8_t device_type, JsonObject & output, const int8_t id) { +bool EMSESP::command_entities(uint8_t device_type, JsonObject output, const int8_t id) { JsonObject node; for (const auto & emsdevice : emsdevices) { @@ -1218,7 +1218,7 @@ bool EMSESP::command_entities(uint8_t device_type, JsonObject & output, const in } // list all available commands, return as json -bool EMSESP::command_commands(uint8_t device_type, JsonObject & output, const int8_t id) { +bool EMSESP::command_commands(uint8_t device_type, JsonObject output, const int8_t id) { return Command::list(device_type, output); } diff --git a/src/emsesp.h b/src/emsesp.h index 3cf337c16..0e8c67fdb 100644 --- a/src/emsesp.h +++ b/src/emsesp.h @@ -125,7 +125,7 @@ class EMSESP { static uint8_t count_devices(); static uint8_t device_index(const uint8_t device_type, const uint8_t unique_id); - static bool get_device_value_info(JsonObject & root, const char * cmd, const int8_t id, const uint8_t devicetype); + static bool get_device_value_info(JsonObject root, const char * cmd, const int8_t id, const uint8_t devicetype); static void show_device_values(uuid::console::Shell & shell); static void show_sensor_values(uuid::console::Shell & shell); @@ -234,8 +234,8 @@ class EMSESP { static void process_version(std::shared_ptr telegram); static void publish_response(std::shared_ptr telegram); static void publish_all_loop(); - static bool command_commands(uint8_t device_type, JsonObject & output, const int8_t id); - static bool command_entities(uint8_t device_type, JsonObject & output, const int8_t id); + static bool command_commands(uint8_t device_type, JsonObject output, const int8_t id); + static bool command_entities(uint8_t device_type, JsonObject output, const int8_t id); static constexpr uint32_t EMS_FETCH_FREQUENCY = 60000; // check every minute static constexpr uint8_t EMS_WAIT_KM_TIMEOUT = 60; // wait one minute diff --git a/src/mqtt.cpp b/src/mqtt.cpp index abc0019d0..a123fdd75 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -668,12 +668,12 @@ bool Mqtt::queue_publish(const char * topic, const std::string & payload) { return queue_publish_message((topic), payload, mqtt_retain_); } -bool Mqtt::queue_publish(const char * topic, const JsonObject & payload) { +bool Mqtt::queue_publish(const char * topic, const JsonObjectConst & payload) { return queue_publish_retain(topic, payload, mqtt_retain_); } // publish json doc, only if its not empty -bool Mqtt::queue_publish(const std::string & topic, const JsonObject & payload) { +bool Mqtt::queue_publish(const std::string & topic, const JsonObjectConst & payload) { return queue_publish_retain(topic, payload, mqtt_retain_); } @@ -683,11 +683,11 @@ bool Mqtt::queue_publish_retain(const char * topic, const std::string & payload, } // publish json doc, only if its not empty, using the retain flag -bool Mqtt::queue_publish_retain(const std::string & topic, const JsonObject & payload, const bool retain) { +bool Mqtt::queue_publish_retain(const std::string & topic, const JsonObjectConst & payload, const bool retain) { return queue_publish_retain(topic.c_str(), payload, retain); } -bool Mqtt::queue_publish_retain(const char * topic, const JsonObject & payload, const bool retain) { +bool Mqtt::queue_publish_retain(const char * topic, const JsonObjectConst & payload, const bool retain) { if (payload.size()) { std::string payload_text; payload_text.reserve(measureJson(payload) + 1); @@ -707,7 +707,7 @@ bool Mqtt::queue_remove_topic(const char * topic) { } // queue a Home Assistant config topic and payload, with retain flag off. -bool Mqtt::queue_ha(const char * topic, const JsonObject & payload) { +bool Mqtt::queue_ha(const char * topic, const JsonObjectConst & payload) { if (!enabled()) { return false; } @@ -788,21 +788,21 @@ bool Mqtt::publish_system_ha_sensor_config(uint8_t type, const char * name, cons // MQTT discovery configs // entity must match the key/value pair in the *_data topic // note: some extra string copying done here, it looks messy but does help with heap fragmentation issues -bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdevice::DeviceValueType - uint8_t tag, // EMSdevice::DeviceValueTAG - const char * const fullname, // fullname, already translated - const char * const en_name, // original name in english - const uint8_t device_type, // EMSdevice::DeviceType - const char * const entity, // same as shortname - const uint8_t uom, // EMSdevice::DeviceValueUOM (0=NONE) - const bool remove, // true if we want to remove this topic - const bool has_cmd, - const char * const ** options, - uint8_t options_size, - const int16_t dv_set_min, - const uint32_t dv_set_max, - const int8_t num_op, - const JsonObject & dev_json) { +bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdevice::DeviceValueType + uint8_t tag, // EMSdevice::DeviceValueTAG + const char * const fullname, // fullname, already translated + const char * const en_name, // original name in english + const uint8_t device_type, // EMSdevice::DeviceType + const char * const entity, // same as shortname + const uint8_t uom, // EMSdevice::DeviceValueUOM (0=NONE) + const bool remove, // true if we want to remove this topic + const bool has_cmd, + const char * const ** options, + uint8_t options_size, + const int16_t dv_set_min, + const uint32_t dv_set_max, + const int8_t num_op, + const JsonObjectConst & dev_json) { // ignore if name (fullname) is empty if (!fullname || !en_name) { return false; diff --git a/src/mqtt.h b/src/mqtt.h index 235a4cd68..eb7d55307 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -67,31 +67,31 @@ class Mqtt { static bool queue_publish(const std::string & topic, const std::string & payload); static bool queue_publish(const char * topic, const char * payload); - static bool queue_publish(const std::string & topic, const JsonObject & payload); - static bool queue_publish(const char * topic, const JsonObject & payload); + static bool queue_publish(const std::string & topic, const JsonObjectConst & payload); + static bool queue_publish(const char * topic, const JsonObjectConst & payload); static bool queue_publish(const char * topic, const std::string & payload); - static bool queue_publish_retain(const std::string & topic, const JsonObject & payload, const bool retain); + static bool queue_publish_retain(const std::string & topic, const JsonObjectConst & payload, const bool retain); static bool queue_publish_retain(const char * topic, const std::string & payload, const bool retain); - static bool queue_publish_retain(const char * topic, const JsonObject & payload, const bool retain); - static bool queue_ha(const char * topic, const JsonObject & payload); + static bool queue_publish_retain(const char * topic, const JsonObjectConst & payload, const bool retain); + static bool queue_ha(const char * topic, const JsonObjectConst & payload); static bool queue_remove_topic(const char * topic); static bool publish_ha_sensor_config(DeviceValue & dv, const char * model, const char * brand, const bool remove, const bool create_device_config = false); - static bool publish_ha_sensor_config(uint8_t type, - uint8_t tag, - const char * const fullname, - const char * const en_name, - const uint8_t device_type, - const char * const entity, - const uint8_t uom, - const bool remove, - const bool has_cmd, - const char * const ** options, - uint8_t options_size, - const int16_t dv_set_min, - const uint32_t dv_set_max, - const int8_t num_op, - const JsonObject & dev_json); + static bool publish_ha_sensor_config(uint8_t type, + uint8_t tag, + const char * const fullname, + const char * const en_name, + const uint8_t device_type, + const char * const entity, + const uint8_t uom, + const bool remove, + const bool has_cmd, + const char * const ** options, + uint8_t options_size, + const int16_t dv_set_min, + const uint32_t dv_set_max, + const int8_t num_op, + const JsonObjectConst & dev_json); static bool publish_system_ha_sensor_config(uint8_t type, const char * name, const char * entity, const uint8_t uom); static bool publish_ha_climate_config(const uint8_t tag, const bool has_roomtemp, const bool remove = false, const int16_t min = 5, const uint32_t max = 30); diff --git a/src/shower.cpp b/src/shower.cpp index 3d37894bb..838de8895 100644 --- a/src/shower.cpp +++ b/src/shower.cpp @@ -35,7 +35,7 @@ void Shower::start() { Command::add( EMSdevice::DeviceType::BOILER, F_(coldshot), - [&](const char * value, const int8_t id, JsonObject & output) { + [&](const char * value, const int8_t id, JsonObject output) { LOG_INFO("Forcing coldshot..."); if (shower_state_) { output["message"] = "OK"; diff --git a/src/system.cpp b/src/system.cpp index 23813e39b..969e6128e 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -95,7 +95,7 @@ bool System::command_send(const char * value, const int8_t id) { return EMSESP::txservice_.send_raw(value); // ignore id } -bool System::command_response(const char * value, const int8_t id, JsonObject & output) { +bool System::command_response(const char * value, const int8_t id, JsonObject output) { JsonDocument doc; if (DeserializationError::Ok == deserializeJson(doc, Mqtt::get_response())) { for (JsonPair p : doc.as()) { @@ -109,7 +109,7 @@ bool System::command_response(const char * value, const int8_t id, JsonObject & // output all the EMS devices and their values, plus the sensors and any custom entities // not scheduler as these are records with no output data -bool System::command_allvalues(const char * value, const int8_t id, JsonObject & output) { +bool System::command_allvalues(const char * value, const int8_t id, JsonObject output) { JsonDocument doc; JsonObject device_output; @@ -629,7 +629,7 @@ void System::send_info_mqtt() { } // create the json for heartbeat -bool System::heartbeat_json(JsonObject & output) { +bool System::heartbeat_json(JsonObject output) { uint8_t bus_status = EMSESP::bus_status(); if (bus_status == EMSESP::BUS_STATUS_TX_ERRORS) { output["bus_status"] = "txerror"; @@ -1165,12 +1165,12 @@ bool System::check_upgrade(bool factory_settings) { } // list commands -bool System::command_commands(const char * value, const int8_t id, JsonObject & output) { +bool System::command_commands(const char * value, const int8_t id, JsonObject output) { return Command::list(EMSdevice::DeviceType::SYSTEM, output); } // convert settings file into json object -void System::extractSettings(const char * filename, const char * section, JsonObject & output) { +void System::extractSettings(const char * filename, const char * section, JsonObject output) { #ifndef EMSESP_STANDALONE File settingsFile = LittleFS.open(filename); if (settingsFile) { @@ -1189,7 +1189,7 @@ void System::extractSettings(const char * filename, const char * section, JsonOb } // save settings file using input from a json object -bool System::saveSettings(const char * filename, const char * section, JsonObject & input) { +bool System::saveSettings(const char * filename, const char * section, JsonObject input) { #ifndef EMSESP_STANDALONE JsonObject section_json = input[section]; if (section_json) { @@ -1207,7 +1207,7 @@ bool System::saveSettings(const char * filename, const char * section, JsonObjec // export status information including the device information // http://ems-esp/api/system/info -bool System::command_info(const char * value, const int8_t id, JsonObject & output) { +bool System::command_info(const char * value, const int8_t id, JsonObject output) { JsonObject node; // System diff --git a/src/system.h b/src/system.h index bf8f5c237..d53853bd1 100644 --- a/src/system.h +++ b/src/system.h @@ -57,10 +57,10 @@ class System { static bool command_restart(const char * value, const int8_t id); static bool command_syslog_level(const char * value, const int8_t id); static bool command_watch(const char * value, const int8_t id); - static bool command_info(const char * value, const int8_t id, JsonObject & output); - static bool command_commands(const char * value, const int8_t id, JsonObject & output); - static bool command_response(const char * value, const int8_t id, JsonObject & output); - static bool command_allvalues(const char * value, const int8_t id, JsonObject & output); + static bool command_info(const char * value, const int8_t id, JsonObject output); + static bool command_commands(const char * value, const int8_t id, JsonObject output); + static bool command_response(const char * value, const int8_t id, JsonObject output); + static bool command_allvalues(const char * value, const int8_t id, JsonObject output); #if defined(EMSESP_TEST) static bool command_test(const char * value, const int8_t id); @@ -79,7 +79,7 @@ class System { void syslog_init(); bool check_upgrade(bool factory_settings); bool check_restore(); - bool heartbeat_json(JsonObject & output); + bool heartbeat_json(JsonObject output); void send_heartbeat(); void send_info_mqtt(); @@ -102,8 +102,8 @@ class System { void button_init(bool refresh); void commands_init(); - static void extractSettings(const char * filename, const char * section, JsonObject & output); - static bool saveSettings(const char * filename, const char * section, JsonObject & input); + static void extractSettings(const char * filename, const char * section, JsonObject output); + static bool saveSettings(const char * filename, const char * section, JsonObject input); static bool is_valid_gpio(uint8_t pin); static bool load_board_profile(std::vector & data, const std::string & board_profile); diff --git a/src/temperaturesensor.cpp b/src/temperaturesensor.cpp index a38c57d3b..fd6a257f2 100644 --- a/src/temperaturesensor.cpp +++ b/src/temperaturesensor.cpp @@ -49,18 +49,18 @@ void TemperatureSensor::start() { Command::add( EMSdevice::DeviceType::TEMPERATURESENSOR, F_(info), - [&](const char * value, const int8_t id, JsonObject & output) { return command_info(value, id, output); }, + [&](const char * value, const int8_t id, JsonObject output) { return command_info(value, id, output); }, FL_(info_cmd)); Command::add( EMSdevice::DeviceType::TEMPERATURESENSOR, F_(values), - [&](const char * value, const int8_t id, JsonObject & output) { return command_info(value, 0, output); }, + [&](const char * value, const int8_t id, JsonObject output) { return command_info(value, 0, output); }, nullptr, CommandFlag::HIDDEN); // this command is hidden Command::add( EMSdevice::DeviceType::TEMPERATURESENSOR, F_(commands), - [&](const char * value, const int8_t id, JsonObject & output) { return command_commands(value, id, output); }, + [&](const char * value, const int8_t id, JsonObject output) { return command_commands(value, id, output); }, FL_(commands_cmd)); char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; @@ -362,13 +362,13 @@ bool TemperatureSensor::updated_values() { } // list commands -bool TemperatureSensor::command_commands(const char * value, const int8_t id, JsonObject & output) { +bool TemperatureSensor::command_commands(const char * value, const int8_t id, JsonObject output) { return Command::list(EMSdevice::DeviceType::TEMPERATURESENSOR, output); } // creates JSON doc from values // returns true if there are no sensors -bool TemperatureSensor::command_info(const char * value, const int8_t id, JsonObject & output) { +bool TemperatureSensor::command_info(const char * value, const int8_t id, JsonObject output) { if (sensors_.empty()) { return true; } @@ -394,7 +394,7 @@ bool TemperatureSensor::command_info(const char * value, const int8_t id, JsonOb } // called from emsesp.cpp, similar to the emsdevice->get_value_info -bool TemperatureSensor::get_value_info(JsonObject & output, const char * cmd, const int8_t id) { +bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, const int8_t id) { if (sensors_.empty()) { return true; } diff --git a/src/temperaturesensor.h b/src/temperaturesensor.h index f4350707f..ba850bf92 100644 --- a/src/temperaturesensor.h +++ b/src/temperaturesensor.h @@ -83,7 +83,7 @@ class TemperatureSensor { void publish_values(const bool force); void reload(); bool updated_values(); - bool get_value_info(JsonObject & output, const char * cmd, const int8_t id); + bool get_value_info(JsonObject output, const char * cmd, const int8_t id); // return back reference to the sensor list, used by other classes std::vector sensors() const { @@ -112,7 +112,7 @@ class TemperatureSensor { bool update(const std::string & id, const std::string & name, int16_t offset); - bool command_info(const char * value, const int8_t id, JsonObject & output); + bool command_info(const char * value, const int8_t id, JsonObject output); #if defined(EMSESP_TEST) void test(); @@ -155,7 +155,7 @@ class TemperatureSensor { uint64_t get_id(const uint8_t addr[]); void remove_ha_topic(const std::string & id); - bool command_commands(const char * value, const int8_t id, JsonObject & output); + bool command_commands(const char * value, const int8_t id, JsonObject output); std::vector sensors_; // our list of active sensors diff --git a/src/web/WebAPIService.cpp b/src/web/WebAPIService.cpp index 1de7230b5..a0a5b493e 100644 --- a/src/web/WebAPIService.cpp +++ b/src/web/WebAPIService.cpp @@ -67,7 +67,7 @@ void WebAPIService::webAPIService_post(AsyncWebServerRequest * request, JsonVari // parse the URL looking for query or path parameters // reporting back any errors -void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) { +void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) { // check if the user has admin privileges (token is included and authorized) bool is_admin = false; EMSESP::webSettingsService.read([&](WebSettings & settings) { diff --git a/src/web/WebAPIService.h b/src/web/WebAPIService.h index 2570317b5..1eb7fcbcf 100644 --- a/src/web/WebAPIService.h +++ b/src/web/WebAPIService.h @@ -49,7 +49,7 @@ class WebAPIService { static uint32_t api_count_; static uint16_t api_fails_; - void parse(AsyncWebServerRequest * request, JsonObject & input); + void parse(AsyncWebServerRequest * request, JsonObject input); void getSettings(AsyncWebServerRequest * request); void getCustomizations(AsyncWebServerRequest * request); diff --git a/src/web/WebCustomEntityService.cpp b/src/web/WebCustomEntityService.cpp index cfe1c9488..a371c745e 100644 --- a/src/web/WebCustomEntityService.cpp +++ b/src/web/WebCustomEntityService.cpp @@ -42,7 +42,7 @@ void WebCustomEntityService::begin() { // this creates the entity file, saving it to the FS // and also calls when the Entity web page is refreshed -void WebCustomEntity::read(WebCustomEntity & webEntity, JsonObject & root) { +void WebCustomEntity::read(WebCustomEntity & webEntity, JsonObject root) { JsonArray entity = root["entities"].to(); uint8_t counter = 0; for (const CustomEntityItem & entityItem : webEntity.customEntityItems) { @@ -62,7 +62,7 @@ void WebCustomEntity::read(WebCustomEntity & webEntity, JsonObject & root) { // call on initialization and also when the Entity web page is updated // this loads the data into the internal class -StateUpdateResult WebCustomEntity::update(JsonObject & root, WebCustomEntity & webCustomEntity) { +StateUpdateResult WebCustomEntity::update(JsonObject root, WebCustomEntity & webCustomEntity) { #ifdef EMSESP_STANDALONE // invoke some fake data for testing // clang-format off @@ -183,7 +183,7 @@ bool WebCustomEntityService::command_setvalue(const char * value, const std::str // output of a single value // if add_uom is true it will add the UOM string to the value -void WebCustomEntityService::render_value(JsonObject & output, CustomEntityItem entity, const bool useVal, const bool web, const bool add_uom) { +void WebCustomEntityService::render_value(JsonObject output, CustomEntityItem entity, const bool useVal, const bool web, const bool add_uom) { char payload[12]; std::string name = useVal ? "value" : entity.name; switch (entity.value_type) { @@ -244,7 +244,7 @@ void WebCustomEntityService::render_value(JsonObject & output, CustomEntityItem // display all custom entities // adding each one, with UOM to a json object string -void WebCustomEntityService::show_values(JsonObject & output) { +void WebCustomEntityService::show_values(JsonObject output) { for (const CustomEntityItem & entity : *customEntityItems) { render_value(output, entity, false, false, true); // with add_uom } @@ -252,7 +252,7 @@ void WebCustomEntityService::show_values(JsonObject & output) { // process json output for info/commands and value_info -bool WebCustomEntityService::get_value_info(JsonObject & output, const char * cmd) { +bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd) { EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; }); if (Helpers::toLower(cmd) == F_(commands)) { output[F_(info)] = Helpers::translated_word(FL_(info_cmd)); @@ -472,7 +472,7 @@ uint8_t WebCustomEntityService::has_commands() { } // send to dashboard, msgpack don't like serialized, use number -void WebCustomEntityService::generate_value_web(JsonObject & output) { +void WebCustomEntityService::generate_value_web(JsonObject output) { EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; }); output["label"] = (std::string) "Custom Entities"; diff --git a/src/web/WebCustomEntityService.h b/src/web/WebCustomEntityService.h index 1b18e2073..27d49a50a 100644 --- a/src/web/WebCustomEntityService.h +++ b/src/web/WebCustomEntityService.h @@ -44,8 +44,8 @@ class WebCustomEntity { public: std::list customEntityItems; - static void read(WebCustomEntity & webEntity, JsonObject & root); - static StateUpdateResult update(JsonObject & root, WebCustomEntity & webEntity); + static void read(WebCustomEntity & webEntity, JsonObject root); + static StateUpdateResult update(JsonObject root, WebCustomEntity & webEntity); }; class WebCustomEntityService : public StatefulService { @@ -56,12 +56,12 @@ class WebCustomEntityService : public StatefulService { void publish_single(const CustomEntityItem & entity); void publish(const bool force = false); bool command_setvalue(const char * value, const std::string name); - bool get_value_info(JsonObject & output, const char * cmd); + bool get_value_info(JsonObject output, const char * cmd); bool get_value(std::shared_ptr telegram); void fetch(); - void render_value(JsonObject & output, CustomEntityItem entity, const bool useVal = false, const bool web = false, const bool add_uom = false); - void show_values(JsonObject & output); - void generate_value_web(JsonObject & output); + void render_value(JsonObject output, CustomEntityItem entity, const bool useVal = false, const bool web = false, const bool add_uom = false); + void show_values(JsonObject output); + void generate_value_web(JsonObject output); uint8_t count_entities(); uint8_t has_commands(); diff --git a/src/web/WebCustomizationService.cpp b/src/web/WebCustomizationService.cpp index 0eb72e688..e69f2132d 100644 --- a/src/web/WebCustomizationService.cpp +++ b/src/web/WebCustomizationService.cpp @@ -55,7 +55,7 @@ WebCustomizationService::WebCustomizationService(AsyncWebServer * server, FS * f } // this creates the customization file, saving it to the FS -void WebCustomization::read(WebCustomization & customizations, JsonObject & root) { +void WebCustomization::read(WebCustomization & customizations, JsonObject root) { // Temperature Sensor customization JsonArray sensorsJson = root["ts"].to(); @@ -95,7 +95,7 @@ void WebCustomization::read(WebCustomization & customizations, JsonObject & root // call on initialization and also when the page is saved via web UI // this loads the data into the internal class -StateUpdateResult WebCustomization::update(JsonObject & root, WebCustomization & customizations) { +StateUpdateResult WebCustomization::update(JsonObject root, WebCustomization & customizations) { #ifdef EMSESP_STANDALONE // invoke some fake data for testing const char * json = "{\"ts\":[],\"as\":[],\"masked_entities\":[{\"product_id\":123,\"device_id\":8,\"entity_ids\":[\"08heatingactive|my custom " diff --git a/src/web/WebCustomizationService.h b/src/web/WebCustomizationService.h index 5044c0005..e757725fb 100644 --- a/src/web/WebCustomizationService.h +++ b/src/web/WebCustomizationService.h @@ -71,8 +71,8 @@ class WebCustomization { std::list sensorCustomizations; // for sensor names and offsets std::list analogCustomizations; // for analog sensors std::list entityCustomizations; // for a list of entities that have a special mask set - static void read(WebCustomization & customizations, JsonObject & root); - static StateUpdateResult update(JsonObject & root, WebCustomization & customizations); + static void read(WebCustomization & customizations, JsonObject root); + static StateUpdateResult update(JsonObject root, WebCustomization & customizations); private: static bool _start; diff --git a/src/web/WebSchedulerService.cpp b/src/web/WebSchedulerService.cpp index ae85767b1..5794f414c 100644 --- a/src/web/WebSchedulerService.cpp +++ b/src/web/WebSchedulerService.cpp @@ -36,7 +36,7 @@ void WebSchedulerService::begin() { // this creates the scheduler file, saving it to the FS // and also calls when the Scheduler web page is refreshed -void WebScheduler::read(WebScheduler & webScheduler, JsonObject & root) { +void WebScheduler::read(WebScheduler & webScheduler, JsonObject root) { JsonArray schedule = root["schedule"].to(); uint8_t counter = 0; for (const ScheduleItem & scheduleItem : webScheduler.scheduleItems) { @@ -53,7 +53,7 @@ void WebScheduler::read(WebScheduler & webScheduler, JsonObject & root) { // call on initialization and also when the Schedule web page is saved // this loads the data into the internal class -StateUpdateResult WebScheduler::update(JsonObject & root, WebScheduler & webScheduler) { +StateUpdateResult WebScheduler::update(JsonObject root, WebScheduler & webScheduler) { #ifdef EMSESP_STANDALONE // invoke some fake data for testing const char * json = @@ -132,7 +132,7 @@ bool WebSchedulerService::command_setvalue(const char * value, const std::string } // process json output for info/commands and value_info -bool WebSchedulerService::get_value_info(JsonObject & output, const char * cmd) { +bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) { EMSESP::webSchedulerService.read([&](WebScheduler & webScheduler) { scheduleItems = &webScheduler.scheduleItems; }); if (Helpers::toLower(cmd) == F_(commands)) { output[F_(info)] = Helpers::translated_word(FL_(info_cmd)); diff --git a/src/web/WebSchedulerService.h b/src/web/WebSchedulerService.h index ef012fc5a..baa19c712 100644 --- a/src/web/WebSchedulerService.h +++ b/src/web/WebSchedulerService.h @@ -43,8 +43,8 @@ class WebScheduler { public: std::list scheduleItems; - static void read(WebScheduler & webScheduler, JsonObject & root); - static StateUpdateResult update(JsonObject & root, WebScheduler & webScheduler); + static void read(WebScheduler & webScheduler, JsonObject root); + static StateUpdateResult update(JsonObject root, WebScheduler & webScheduler); }; class WebSchedulerService : public StatefulService { @@ -57,7 +57,7 @@ class WebSchedulerService : public StatefulService { void publish(const bool force = false); bool has_commands(); bool command_setvalue(const char * value, const std::string name); - bool get_value_info(JsonObject & output, const char * cmd); + bool get_value_info(JsonObject output, const char * cmd); void ha_reset() { ha_registered_ = false; } diff --git a/src/web/WebSettingsService.cpp b/src/web/WebSettingsService.cpp index 69ad73e9b..206df1829 100644 --- a/src/web/WebSettingsService.cpp +++ b/src/web/WebSettingsService.cpp @@ -35,7 +35,7 @@ WebSettingsService::WebSettingsService(AsyncWebServer * server, FS * fs, Securit addUpdateHandler([&](const String & originId) { onUpdate(); }, false); } -void WebSettings::read(WebSettings & settings, JsonObject & root) { +void WebSettings::read(WebSettings & settings, JsonObject root) { root["version"] = settings.version; root["locale"] = settings.locale; root["tx_mode"] = settings.tx_mode; @@ -80,7 +80,7 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) { } // call on initialization and also when settings are updated via web or console -StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) { +StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) { // load the version of the settings // will be picked up in System::check_upgrade() settings.version = root["version"] | EMSESP_DEFAULT_VERSION; diff --git a/src/web/WebSettingsService.h b/src/web/WebSettingsService.h index c887cdf09..f62815d48 100644 --- a/src/web/WebSettingsService.h +++ b/src/web/WebSettingsService.h @@ -71,8 +71,8 @@ class WebSettings { uint8_t eth_phy_addr; uint8_t eth_clock_mode; - static void read(WebSettings & settings, JsonObject & root); - static StateUpdateResult update(JsonObject & root, WebSettings & settings); + static void read(WebSettings & settings, JsonObject root); + static StateUpdateResult update(JsonObject root, WebSettings & settings); enum ChangeFlags : uint8_t {