remove obsolete reference to JsonObject

This commit is contained in:
Proddy
2024-01-06 17:42:42 +01:00
parent 778cdaabb6
commit 10d6728c82
41 changed files with 170 additions and 170 deletions

View File

@@ -75,7 +75,7 @@ class APSettings {
&& subnetMask == settings.subnetMask; && subnetMask == settings.subnetMask;
} }
static void read(APSettings & settings, JsonObject & root) { static void read(APSettings & settings, JsonObject root) {
root["provision_mode"] = settings.provisionMode; root["provision_mode"] = settings.provisionMode;
root["ssid"] = settings.ssid; root["ssid"] = settings.ssid;
root["password"] = settings.password; root["password"] = settings.password;
@@ -87,7 +87,7 @@ class APSettings {
root["subnet_mask"] = settings.subnetMask.toString(); root["subnet_mask"] = settings.subnetMask.toString();
} }
static StateUpdateResult update(JsonObject & root, APSettings & settings) { static StateUpdateResult update(JsonObject root, APSettings & settings) {
APSettings newSettings = {}; APSettings newSettings = {};
newSettings.provisionMode = root["provision_mode"] | FACTORY_AP_PROVISION_MODE; newSettings.provisionMode = root["provision_mode"] | FACTORY_AP_PROVISION_MODE;
switch (settings.provisionMode) { switch (settings.provisionMode) {

View File

@@ -34,7 +34,7 @@ String ArduinoJsonJWT::sign(String & payload) {
return encode((char *)hmacResult, 32); return encode((char *)hmacResult, 32);
} }
String ArduinoJsonJWT::buildJWT(JsonObject & payload) { String ArduinoJsonJWT::buildJWT(JsonObject payload) {
// serialize, then encode payload // serialize, then encode payload
String jwt; String jwt;
serializeJson(payload, jwt); serializeJson(payload, jwt);

View File

@@ -25,7 +25,7 @@ class ArduinoJsonJWT {
void setSecret(String secret); void setSecret(String secret);
String getSecret(); String getSecret();
String buildJWT(JsonObject & payload); String buildJWT(JsonObject payload);
void parseJWT(String jwt, JsonDocument & jsonDocument); void parseJWT(String jwt, JsonDocument & jsonDocument);
}; };

View File

@@ -8,19 +8,19 @@
class JsonUtils { class JsonUtils {
public: 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 = {}; IPAddress defaultIp = {};
if (!defaultIp.fromString(def)) { if (!defaultIp.fromString(def)) {
defaultIp = INADDR_NONE; defaultIp = INADDR_NONE;
} }
readIP(root, key, ip, defaultIp); 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<String>() || !ip.fromString(root[key].as<String>())) { if (!root[key].is<String>() || !ip.fromString(root[key].as<String>())) {
ip = defaultIp; 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)) { if (IPUtils::isSet(ip)) {
root[key] = ip.toString(); root[key] = ip.toString();
} }

View File

@@ -216,7 +216,7 @@ bool MqttSettingsService::configureMqtt() {
return false; return false;
} }
void MqttSettings::read(MqttSettings & settings, JsonObject & root) { void MqttSettings::read(MqttSettings & settings, JsonObject root) {
#if CONFIG_IDF_TARGET_ESP32S3 #if CONFIG_IDF_TARGET_ESP32S3
#ifndef TASMOTA_SDK #ifndef TASMOTA_SDK
root["enableTLS"] = settings.enableTLS; root["enableTLS"] = settings.enableTLS;
@@ -252,7 +252,7 @@ void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
root["send_response"] = settings.send_response; root["send_response"] = settings.send_response;
} }
StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & settings) { StateUpdateResult MqttSettings::update(JsonObject root, MqttSettings & settings) {
MqttSettings newSettings = {}; MqttSettings newSettings = {};
bool changed = false; bool changed = false;

View File

@@ -97,8 +97,8 @@ class MqttSettings {
bool send_response; bool send_response;
uint8_t entity_format; uint8_t entity_format;
static void read(MqttSettings & settings, JsonObject & root); static void read(MqttSettings & settings, JsonObject root);
static StateUpdateResult update(JsonObject & root, MqttSettings & settings); static StateUpdateResult update(JsonObject root, MqttSettings & settings);
}; };
class MqttSettingsService : public StatefulService<MqttSettings> { class MqttSettingsService : public StatefulService<MqttSettings> {

View File

@@ -36,14 +36,14 @@ class NTPSettings {
String tzFormat; String tzFormat;
String server; String server;
static void read(NTPSettings & settings, JsonObject & root) { static void read(NTPSettings & settings, JsonObject root) {
root["enabled"] = settings.enabled; root["enabled"] = settings.enabled;
root["server"] = settings.server; root["server"] = settings.server;
root["tz_label"] = settings.tzLabel; root["tz_label"] = settings.tzLabel;
root["tz_format"] = settings.tzFormat; 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.enabled = root["enabled"] | FACTORY_NTP_ENABLED;
settings.server = root["server"] | FACTORY_NTP_SERVER; settings.server = root["server"] | FACTORY_NTP_SERVER;
settings.tzLabel = root["tz_label"] | FACTORY_NTP_TIME_ZONE_LABEL; settings.tzLabel = root["tz_label"] | FACTORY_NTP_TIME_ZONE_LABEL;

View File

@@ -50,7 +50,7 @@ class NetworkSettings {
IPAddress dnsIP1; IPAddress dnsIP1;
IPAddress dnsIP2; IPAddress dnsIP2;
static void read(NetworkSettings & settings, JsonObject & root) { static void read(NetworkSettings & settings, JsonObject root) {
// connection settings // connection settings
root["ssid"] = settings.ssid; root["ssid"] = settings.ssid;
root["bssid"] = settings.bssid; root["bssid"] = settings.bssid;
@@ -73,7 +73,7 @@ class NetworkSettings {
JsonUtils::writeIP(root, "dns_ip_2", settings.dnsIP2); 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 enableCORS = settings.enableCORS;
auto CORSOrigin = settings.CORSOrigin; auto CORSOrigin = settings.CORSOrigin;
auto ssid = settings.ssid; auto ssid = settings.ssid;

View File

@@ -28,13 +28,13 @@ class OTASettings {
int port; int port;
String password; String password;
static void read(OTASettings & settings, JsonObject & root) { static void read(OTASettings & settings, JsonObject root) {
root["enabled"] = settings.enabled; root["enabled"] = settings.enabled;
root["port"] = settings.port; root["port"] = settings.port;
root["password"] = settings.password; 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.enabled = root["enabled"] | FACTORY_OTA_ENABLED;
settings.port = root["port"] | FACTORY_OTA_PORT; settings.port = root["port"] | FACTORY_OTA_PORT;
settings.password = root["password"] | FACTORY_OTA_PASSWORD; settings.password = root["password"] | FACTORY_OTA_PASSWORD;

View File

@@ -63,12 +63,12 @@ Authentication SecuritySettingsService::authenticate(const String & username, co
return Authentication(); return Authentication();
} }
inline void populateJWTPayload(JsonObject & payload, User * user) { inline void populateJWTPayload(JsonObject payload, User * user) {
payload["username"] = user->username; payload["username"] = user->username;
payload["admin"] = user->admin; payload["admin"] = user->admin;
} }
boolean SecuritySettingsService::validatePayload(JsonObject & parsedPayload, User * user) { boolean SecuritySettingsService::validatePayload(JsonObject parsedPayload, User * user) {
JsonDocument jsonDocument; JsonDocument jsonDocument;
JsonObject payload = jsonDocument.to<JsonObject>(); JsonObject payload = jsonDocument.to<JsonObject>();
populateJWTPayload(payload, user); populateJWTPayload(payload, user);

View File

@@ -35,7 +35,7 @@ class SecuritySettings {
String jwtSecret; String jwtSecret;
std::list<User> users; std::list<User> users;
static void read(SecuritySettings & settings, JsonObject & root) { static void read(SecuritySettings & settings, JsonObject root) {
// secret // secret
root["jwt_secret"] = settings.jwtSecret; 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 // secret
settings.jwtSecret = root["jwt_secret"] | FACTORY_JWT_SECRET; settings.jwtSecret = root["jwt_secret"] | FACTORY_JWT_SECRET;
@@ -98,7 +98,7 @@ class SecuritySettingsService : public StatefulService<SecuritySettings>, public
/* /*
* Verify the payload is correct * Verify the payload is correct
*/ */
boolean validatePayload(JsonObject & parsedPayload, User * user); boolean validatePayload(JsonObject parsedPayload, User * user);
}; };
#else #else

View File

@@ -17,10 +17,10 @@ enum class StateUpdateResult {
}; };
template <typename T> template <typename T>
using JsonStateUpdater = std::function<StateUpdateResult(JsonObject & root, T & settings)>; using JsonStateUpdater = std::function<StateUpdateResult(JsonObject root, T & settings)>;
template <typename T> template <typename T>
using JsonStateReader = std::function<void(T & settings, JsonObject & root)>; using JsonStateReader = std::function<void(T & settings, JsonObject root)>;
typedef size_t update_handler_id_t; typedef size_t update_handler_id_t;
typedef std::function<void(const String & originId)> StateUpdateCallback; typedef std::function<void(const String & originId)> StateUpdateCallback;
@@ -81,7 +81,7 @@ class StatefulService {
return result; return result;
} }
StateUpdateResult update(JsonObject & jsonObject, JsonStateUpdater<T> stateUpdater, const String & originId) { StateUpdateResult update(JsonObject jsonObject, JsonStateUpdater<T> stateUpdater, const String & originId) {
beginTransaction(); beginTransaction();
StateUpdateResult result = stateUpdater(jsonObject, _state); StateUpdateResult result = stateUpdater(jsonObject, _state);
endTransaction(); endTransaction();
@@ -91,7 +91,7 @@ class StatefulService {
return result; return result;
} }
StateUpdateResult updateWithoutPropagation(JsonObject & jsonObject, JsonStateUpdater<T> stateUpdater) { StateUpdateResult updateWithoutPropagation(JsonObject jsonObject, JsonStateUpdater<T> stateUpdater) {
beginTransaction(); beginTransaction();
StateUpdateResult result = stateUpdater(jsonObject, _state); StateUpdateResult result = stateUpdater(jsonObject, _state);
endTransaction(); endTransaction();
@@ -104,7 +104,7 @@ class StatefulService {
endTransaction(); endTransaction();
} }
void read(JsonObject & jsonObject, JsonStateReader<T> stateReader) { void read(JsonObject jsonObject, JsonStateReader<T> stateReader) {
beginTransaction(); beginTransaction();
stateReader(_state, jsonObject); stateReader(_state, jsonObject);
endTransaction(); endTransaction();

View File

@@ -75,10 +75,10 @@ class DummySettings {
bool enableCORS = false; bool enableCORS = false;
String CORSOrigin = "*"; String CORSOrigin = "*";
static void read(DummySettings & settings, JsonObject & root){}; static void read(DummySettings & settings, JsonObject root){};
static void read(DummySettings & settings){}; static void read(DummySettings & settings){};
static StateUpdateResult update(JsonObject & root, DummySettings & settings) { static StateUpdateResult update(JsonObject root, DummySettings & settings) {
return StateUpdateResult::CHANGED; return StateUpdateResult::CHANGED;
} }
}; };
@@ -152,7 +152,7 @@ class EMSESPSettingsService {
class JsonUtils { class JsonUtils {
public: 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; root[key] = ip;
} }
}; };

View File

@@ -62,12 +62,12 @@ Authentication SecuritySettingsService::authenticate(const String & username, co
return Authentication(); return Authentication();
} }
inline void populateJWTPayload(JsonObject & payload, User * user) { inline void populateJWTPayload(JsonObject payload, User * user) {
payload["username"] = user->username; payload["username"] = user->username;
payload["admin"] = user->admin; payload["admin"] = user->admin;
} }
boolean SecuritySettingsService::validatePayload(JsonObject & parsedPayload, User * user) { boolean SecuritySettingsService::validatePayload(JsonObject parsedPayload, User * user) {
JsonDocument jsonDocument; JsonDocument jsonDocument;
JsonObject payload = jsonDocument.to<JsonObject>(); JsonObject payload = jsonDocument.to<JsonObject>();
populateJWTPayload(payload, user); populateJWTPayload(payload, user);

View File

@@ -32,7 +32,7 @@ class SecuritySettings {
String jwtSecret; String jwtSecret;
std::list<User> users; std::list<User> users;
static void read(SecuritySettings & settings, JsonObject & root) { static void read(SecuritySettings & settings, JsonObject root) {
// secret // secret
root["jwt_secret"] = settings.jwtSecret; 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 // secret
settings.jwtSecret = root["jwt_secret"] | FACTORY_JWT_SECRET; settings.jwtSecret = root["jwt_secret"] | FACTORY_JWT_SECRET;
@@ -85,7 +85,7 @@ class SecuritySettingsService : public StatefulService<SecuritySettings>, public
void configureJWTHandler(); void configureJWTHandler();
Authentication authenticateJWT(String & jwt); Authentication authenticateJWT(String & jwt);
boolean validatePayload(JsonObject & parsedPayload, User * user); boolean validatePayload(JsonObject parsedPayload, User * user);
}; };
#else #else

View File

@@ -15,10 +15,10 @@ enum class StateUpdateResult {
}; };
template <typename T> template <typename T>
using JsonStateUpdater = std::function<StateUpdateResult(JsonObject & root, T & settings)>; using JsonStateUpdater = std::function<StateUpdateResult(JsonObject root, T & settings)>;
template <typename T> template <typename T>
using JsonStateReader = std::function<void(T & settings, JsonObject & root)>; using JsonStateReader = std::function<void(T & settings, JsonObject root)>;
typedef size_t update_handler_id_t; typedef size_t update_handler_id_t;
typedef std::function<void(const String & originId)> StateUpdateCallback; typedef std::function<void(const String & originId)> StateUpdateCallback;
@@ -85,7 +85,7 @@ class StatefulService {
return result; return result;
} }
StateUpdateResult update(JsonObject & jsonObject, JsonStateUpdater<T> stateUpdater, const String & originId) { StateUpdateResult update(JsonObject jsonObject, JsonStateUpdater<T> stateUpdater, const String & originId) {
beginTransaction(); beginTransaction();
StateUpdateResult result = stateUpdater(jsonObject, _state); StateUpdateResult result = stateUpdater(jsonObject, _state);
endTransaction(); endTransaction();
@@ -95,7 +95,7 @@ class StatefulService {
return result; return result;
} }
StateUpdateResult updateWithoutPropagation(JsonObject & jsonObject, JsonStateUpdater<T> stateUpdater) { StateUpdateResult updateWithoutPropagation(JsonObject jsonObject, JsonStateUpdater<T> stateUpdater) {
beginTransaction(); beginTransaction();
StateUpdateResult result = stateUpdater(jsonObject, _state); StateUpdateResult result = stateUpdater(jsonObject, _state);
endTransaction(); endTransaction();
@@ -108,7 +108,7 @@ class StatefulService {
endTransaction(); endTransaction();
} }
void read(JsonObject & jsonObject, JsonStateReader<T> stateReader) { void read(JsonObject jsonObject, JsonStateReader<T> stateReader) {
beginTransaction(); beginTransaction();
stateReader(_state, jsonObject); stateReader(_state, jsonObject);
endTransaction(); endTransaction();

View File

@@ -37,12 +37,12 @@ void AnalogSensor::start() {
Command::add( Command::add(
EMSdevice::DeviceType::ANALOGSENSOR, EMSdevice::DeviceType::ANALOGSENSOR,
F_(info), 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)); FL_(info_cmd));
Command::add( Command::add(
EMSdevice::DeviceType::ANALOGSENSOR, EMSdevice::DeviceType::ANALOGSENSOR,
F_(values), 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, nullptr,
CommandFlag::HIDDEN); // this command is hidden CommandFlag::HIDDEN); // this command is hidden
Command::add( Command::add(
@@ -54,7 +54,7 @@ void AnalogSensor::start() {
Command::add( Command::add(
EMSdevice::DeviceType::ANALOGSENSOR, EMSdevice::DeviceType::ANALOGSENSOR,
F_(commands), 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)); FL_(commands_cmd));
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; 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 // called from emsesp.cpp, similar to the emsdevice->get_value_info
// searches by name // 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()) { if (sensors_.empty()) {
return true; return true;
} }
@@ -699,7 +699,7 @@ bool AnalogSensor::get_value_info(JsonObject & output, const char * cmd, const i
// creates JSON doc from values // creates JSON doc from values
// returns true if there are no sensors // 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()) { if (sensors_.empty()) {
return true; return true;
} }
@@ -851,7 +851,7 @@ bool AnalogSensor::command_setvalue(const char * value, const int8_t gpio) {
} }
// list commands // 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); return Command::list(EMSdevice::DeviceType::ANALOGSENSOR, output);
} }

View File

@@ -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 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(); 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) #if defined(EMSESP_TEST)
@@ -172,7 +172,7 @@ class AnalogSensor {
void remove_ha_topic(const int8_t type, const uint8_t id) const; void remove_ha_topic(const int8_t type, const uint8_t id) const;
bool command_setvalue(const char * value, const int8_t gpio); bool command_setvalue(const char * value, const int8_t gpio);
void measure(); 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<Sensor> sensors_; // our list of sensors std::vector<Sensor> sensors_; // our list of sensors

View File

@@ -30,7 +30,7 @@ std::vector<Command::CmdFunction> Command::cmdfunctions_;
// the path is leading so if duplicate keys are in the input JSON it will be ignored // 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 (<base>/) // the entry point will be either via the Web API (api/) or MQTT (<base>/)
// returns a return code and json output // 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 SUrlParser p; // parse URL for the path names
p.parse(path); 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. // calls a command. Takes a json object for output.
// id may be used to represent a heating circuit for example // 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 // 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) { if (cmd == nullptr) {
return CommandRet::NOT_FOUND; 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 // 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()) { if (cmdfunctions_.empty()) {
output["message"] = "no commands available"; output["message"] = "no commands available";
return false; return false;

View File

@@ -49,7 +49,7 @@ enum CommandRet : uint8_t {
}; };
using cmd_function_p = std::function<bool(const char * data, const int8_t id)>; using cmd_function_p = std::function<bool(const char * data, const int8_t id)>;
using cmd_json_function_p = std::function<bool(const char * data, const int8_t id, JsonObject & output)>; using cmd_json_function_p = std::function<bool(const char * data, const int8_t id, JsonObject output)>;
class Command { class Command {
public: public:
@@ -96,7 +96,7 @@ class Command {
return cmdfunctions_; 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); 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 // 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 void show_devices(uuid::console::Shell & shell);
static bool device_has_commands(const uint8_t device_type); 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); static const char * parse_command_string(const char * command, int8_t & id);
@@ -142,7 +142,7 @@ class Command {
static std::vector<CmdFunction> cmdfunctions_; // the list of commands static std::vector<CmdFunction> 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.clear();
output["message"] = message; output["message"] = message;
return error_code; return error_code;

View File

@@ -366,7 +366,7 @@ bool EMSdevice::has_cmd(const char * cmd, const int8_t id) const {
// list of registered device entries // list of registered device entries
// called from the command 'entities' // 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_) { for (const auto & dv : devicevalues_) {
auto fullname = dv.get_fullname(); auto fullname = dv.get_fullname();
if (!dv.has_state(DeviceValueState::DV_WEB_EXCLUDE) && dv.type != DeviceValueType::CMD && !fullname.empty()) { 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 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; bool has_value = false;
uint8_t tag; uint8_t tag;
if (id >= 1 && id <= (1 + DeviceValueTAG::TAG_HS16 - DeviceValueTAG::TAG_HC1)) { 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 // 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 // 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 // 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"] = to_string_short();
// output["label"] = name_; // output["label"] = name_;
JsonArray data = output["data"].to<JsonArray>(); JsonArray data = output["data"].to<JsonArray>();
@@ -1362,7 +1362,7 @@ void EMSdevice::dump_value_info() {
// builds json for a specific device value / entity // builds json for a specific device value / entity
// cmd is the endpoint or name of the device entity // cmd is the endpoint or name of the device entity
// returns false if failed, otherwise true // 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; JsonObject json = output;
int8_t tag = id; 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 // 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 the MQTT payloads, Console messages and Web API calls // 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 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 uint8_t old_tag = 255; // NAN
JsonObject json = output; JsonObject json = output;

View File

@@ -51,7 +51,7 @@ class EMSdevice {
static const char * uom_to_string(uint8_t uom); static const char * uom_to_string(uint8_t uom);
static const char * tag_to_mqtt(uint8_t tag); static const char * tag_to_mqtt(uint8_t tag);
static uint8_t decode_brand(uint8_t value); 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 // non static
@@ -204,7 +204,7 @@ class EMSdevice {
void show_telegram_handlers(uuid::console::Shell & shell) const; void show_telegram_handlers(uuid::console::Shell & shell) const;
char * show_telegram_handlers(char * result, const size_t len, const uint8_t handlers); char * show_telegram_handlers(char * result, const size_t len, const uint8_t handlers);
void show_mqtt_handlers(uuid::console::Shell & shell) const; 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 add_handlers_ignored(const uint16_t handler);
void set_climate_minmax(uint8_t tag, int16_t min, uint32_t max); 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; std::string get_value_uom(const std::string & shortname) const;
bool get_value_info(JsonObject & root, const char * cmd, const int8_t id); bool get_value_info(JsonObject root, const char * cmd, const int8_t id);
void get_dv_info(JsonObject & json); void get_dv_info(JsonObject json);
enum OUTPUT_TARGET : uint8_t { API_VERBOSE, API_SHORTNAMES, MQTT, CONSOLE }; 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); 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(JsonObject output);
void generate_values_web_customization(JsonArray & output); void generate_values_web_customization(JsonArray & output);
void add_device_value(uint8_t tag, void add_device_value(uint8_t tag,

View File

@@ -662,7 +662,7 @@ void EMSESP::publish_response(std::shared_ptr<const Telegram> telegram) {
// builds json with the detail of each value, // builds json with the detail of each value,
// for a specific EMS device type or the sensors, scheduler and custom entities // 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) { for (const auto & emsdevice : emsdevices) {
if (emsdevice->device_type() == devicetype) { if (emsdevice->device_type() == devicetype) {
if (emsdevice->get_value_info(root, cmd, id)) { 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( Command::add(
device_type, device_type,
F_(info), 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); return EMSdevice::export_values(device_type, output, id, EMSdevice::OUTPUT_TARGET::API_VERBOSE);
}, },
FL_(info_cmd)); FL_(info_cmd));
Command::add( Command::add(
device_type, device_type,
F_(values), 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, return EMSdevice::export_values(device_type,
output, output,
id, id,
@@ -1188,12 +1188,12 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
Command::add( Command::add(
device_type, device_type,
F_(commands), 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)); FL_(commands_cmd));
Command::add( Command::add(
device_type, device_type,
F_(entities), 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)); FL_(entities_cmd));
// MQTT subscribe to the device e.g. "ems-esp/boiler/#" // 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 // 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; JsonObject node;
for (const auto & emsdevice : emsdevices) { 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 // 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); return Command::list(device_type, output);
} }

View File

@@ -125,7 +125,7 @@ class EMSESP {
static uint8_t count_devices(); static uint8_t count_devices();
static uint8_t device_index(const uint8_t device_type, const uint8_t unique_id); 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_device_values(uuid::console::Shell & shell);
static void show_sensor_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<const Telegram> telegram); static void process_version(std::shared_ptr<const Telegram> telegram);
static void publish_response(std::shared_ptr<const Telegram> telegram); static void publish_response(std::shared_ptr<const Telegram> telegram);
static void publish_all_loop(); static void publish_all_loop();
static bool command_commands(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 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 uint32_t EMS_FETCH_FREQUENCY = 60000; // check every minute
static constexpr uint8_t EMS_WAIT_KM_TIMEOUT = 60; // wait one minute static constexpr uint8_t EMS_WAIT_KM_TIMEOUT = 60; // wait one minute

View File

@@ -668,12 +668,12 @@ bool Mqtt::queue_publish(const char * topic, const std::string & payload) {
return queue_publish_message((topic), payload, mqtt_retain_); 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_); return queue_publish_retain(topic, payload, mqtt_retain_);
} }
// publish json doc, only if its not empty // 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_); 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 // 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); 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()) { if (payload.size()) {
std::string payload_text; std::string payload_text;
payload_text.reserve(measureJson(payload) + 1); 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. // 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()) { if (!enabled()) {
return false; return false;
} }
@@ -788,21 +788,21 @@ bool Mqtt::publish_system_ha_sensor_config(uint8_t type, const char * name, cons
// MQTT discovery configs // MQTT discovery configs
// entity must match the key/value pair in the *_data topic // 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 // 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 bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdevice::DeviceValueType
uint8_t tag, // EMSdevice::DeviceValueTAG uint8_t tag, // EMSdevice::DeviceValueTAG
const char * const fullname, // fullname, already translated const char * const fullname, // fullname, already translated
const char * const en_name, // original name in english const char * const en_name, // original name in english
const uint8_t device_type, // EMSdevice::DeviceType const uint8_t device_type, // EMSdevice::DeviceType
const char * const entity, // same as shortname const char * const entity, // same as shortname
const uint8_t uom, // EMSdevice::DeviceValueUOM (0=NONE) const uint8_t uom, // EMSdevice::DeviceValueUOM (0=NONE)
const bool remove, // true if we want to remove this topic const bool remove, // true if we want to remove this topic
const bool has_cmd, const bool has_cmd,
const char * const ** options, const char * const ** options,
uint8_t options_size, uint8_t options_size,
const int16_t dv_set_min, const int16_t dv_set_min,
const uint32_t dv_set_max, const uint32_t dv_set_max,
const int8_t num_op, const int8_t num_op,
const JsonObject & dev_json) { const JsonObjectConst & dev_json) {
// ignore if name (fullname) is empty // ignore if name (fullname) is empty
if (!fullname || !en_name) { if (!fullname || !en_name) {
return false; return false;

View File

@@ -67,31 +67,31 @@ class Mqtt {
static bool queue_publish(const std::string & topic, const std::string & payload); 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 char * topic, const char * payload);
static bool queue_publish(const std::string & topic, const JsonObject & payload); static bool queue_publish(const std::string & topic, const JsonObjectConst & payload);
static bool queue_publish(const char * topic, const JsonObject & 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(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 std::string & payload, const bool retain);
static bool queue_publish_retain(const char * topic, const JsonObject & payload, const bool retain); static bool queue_publish_retain(const char * topic, const JsonObjectConst & payload, const bool retain);
static bool queue_ha(const char * topic, const JsonObject & payload); static bool queue_ha(const char * topic, const JsonObjectConst & payload);
static bool queue_remove_topic(const char * topic); 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(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, static bool publish_ha_sensor_config(uint8_t type,
uint8_t tag, uint8_t tag,
const char * const fullname, const char * const fullname,
const char * const en_name, const char * const en_name,
const uint8_t device_type, const uint8_t device_type,
const char * const entity, const char * const entity,
const uint8_t uom, const uint8_t uom,
const bool remove, const bool remove,
const bool has_cmd, const bool has_cmd,
const char * const ** options, const char * const ** options,
uint8_t options_size, uint8_t options_size,
const int16_t dv_set_min, const int16_t dv_set_min,
const uint32_t dv_set_max, const uint32_t dv_set_max,
const int8_t num_op, const int8_t num_op,
const JsonObject & dev_json); 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_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); 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);

View File

@@ -35,7 +35,7 @@ void Shower::start() {
Command::add( Command::add(
EMSdevice::DeviceType::BOILER, EMSdevice::DeviceType::BOILER,
F_(coldshot), F_(coldshot),
[&](const char * value, const int8_t id, JsonObject & output) { [&](const char * value, const int8_t id, JsonObject output) {
LOG_INFO("Forcing coldshot..."); LOG_INFO("Forcing coldshot...");
if (shower_state_) { if (shower_state_) {
output["message"] = "OK"; output["message"] = "OK";

View File

@@ -95,7 +95,7 @@ bool System::command_send(const char * value, const int8_t id) {
return EMSESP::txservice_.send_raw(value); // ignore 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; JsonDocument doc;
if (DeserializationError::Ok == deserializeJson(doc, Mqtt::get_response())) { if (DeserializationError::Ok == deserializeJson(doc, Mqtt::get_response())) {
for (JsonPair p : doc.as<JsonObject>()) { for (JsonPair p : doc.as<JsonObject>()) {
@@ -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 // 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 // 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; JsonDocument doc;
JsonObject device_output; JsonObject device_output;
@@ -629,7 +629,7 @@ void System::send_info_mqtt() {
} }
// create the json for heartbeat // create the json for heartbeat
bool System::heartbeat_json(JsonObject & output) { bool System::heartbeat_json(JsonObject output) {
uint8_t bus_status = EMSESP::bus_status(); uint8_t bus_status = EMSESP::bus_status();
if (bus_status == EMSESP::BUS_STATUS_TX_ERRORS) { if (bus_status == EMSESP::BUS_STATUS_TX_ERRORS) {
output["bus_status"] = "txerror"; output["bus_status"] = "txerror";
@@ -1165,12 +1165,12 @@ bool System::check_upgrade(bool factory_settings) {
} }
// list commands // 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); return Command::list(EMSdevice::DeviceType::SYSTEM, output);
} }
// convert settings file into json object // 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 #ifndef EMSESP_STANDALONE
File settingsFile = LittleFS.open(filename); File settingsFile = LittleFS.open(filename);
if (settingsFile) { 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 // 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 #ifndef EMSESP_STANDALONE
JsonObject section_json = input[section]; JsonObject section_json = input[section];
if (section_json) { if (section_json) {
@@ -1207,7 +1207,7 @@ bool System::saveSettings(const char * filename, const char * section, JsonObjec
// export status information including the device information // export status information including the device information
// http://ems-esp/api/system/info // 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; JsonObject node;
// System // System

View File

@@ -57,10 +57,10 @@ class System {
static bool command_restart(const char * value, const int8_t id); 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_syslog_level(const char * value, const int8_t id);
static bool command_watch(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_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_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_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_allvalues(const char * value, const int8_t id, JsonObject output);
#if defined(EMSESP_TEST) #if defined(EMSESP_TEST)
static bool command_test(const char * value, const int8_t id); static bool command_test(const char * value, const int8_t id);
@@ -79,7 +79,7 @@ class System {
void syslog_init(); void syslog_init();
bool check_upgrade(bool factory_settings); bool check_upgrade(bool factory_settings);
bool check_restore(); bool check_restore();
bool heartbeat_json(JsonObject & output); bool heartbeat_json(JsonObject output);
void send_heartbeat(); void send_heartbeat();
void send_info_mqtt(); void send_info_mqtt();
@@ -102,8 +102,8 @@ class System {
void button_init(bool refresh); void button_init(bool refresh);
void commands_init(); void commands_init();
static void extractSettings(const char * filename, const char * section, JsonObject & output); static void extractSettings(const char * filename, const char * section, JsonObject output);
static bool saveSettings(const char * filename, const char * section, JsonObject & input); static bool saveSettings(const char * filename, const char * section, JsonObject input);
static bool is_valid_gpio(uint8_t pin); static bool is_valid_gpio(uint8_t pin);
static bool load_board_profile(std::vector<int8_t> & data, const std::string & board_profile); static bool load_board_profile(std::vector<int8_t> & data, const std::string & board_profile);

View File

@@ -49,18 +49,18 @@ void TemperatureSensor::start() {
Command::add( Command::add(
EMSdevice::DeviceType::TEMPERATURESENSOR, EMSdevice::DeviceType::TEMPERATURESENSOR,
F_(info), 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)); FL_(info_cmd));
Command::add( Command::add(
EMSdevice::DeviceType::TEMPERATURESENSOR, EMSdevice::DeviceType::TEMPERATURESENSOR,
F_(values), 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, nullptr,
CommandFlag::HIDDEN); // this command is hidden CommandFlag::HIDDEN); // this command is hidden
Command::add( Command::add(
EMSdevice::DeviceType::TEMPERATURESENSOR, EMSdevice::DeviceType::TEMPERATURESENSOR,
F_(commands), 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)); FL_(commands_cmd));
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
@@ -362,13 +362,13 @@ bool TemperatureSensor::updated_values() {
} }
// list commands // 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); return Command::list(EMSdevice::DeviceType::TEMPERATURESENSOR, output);
} }
// creates JSON doc from values // creates JSON doc from values
// returns true if there are no sensors // 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()) { if (sensors_.empty()) {
return true; 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 // 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()) { if (sensors_.empty()) {
return true; return true;
} }

View File

@@ -83,7 +83,7 @@ class TemperatureSensor {
void publish_values(const bool force); void publish_values(const bool force);
void reload(); void reload();
bool updated_values(); 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 // return back reference to the sensor list, used by other classes
std::vector<Sensor> sensors() const { std::vector<Sensor> sensors() const {
@@ -112,7 +112,7 @@ class TemperatureSensor {
bool update(const std::string & id, const std::string & name, int16_t offset); 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) #if defined(EMSESP_TEST)
void test(); void test();
@@ -155,7 +155,7 @@ class TemperatureSensor {
uint64_t get_id(const uint8_t addr[]); uint64_t get_id(const uint8_t addr[]);
void remove_ha_topic(const std::string & id); 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<Sensor> sensors_; // our list of active sensors std::vector<Sensor> sensors_; // our list of active sensors

View File

@@ -67,7 +67,7 @@ void WebAPIService::webAPIService_post(AsyncWebServerRequest * request, JsonVari
// parse the URL looking for query or path parameters // parse the URL looking for query or path parameters
// reporting back any errors // 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) // check if the user has admin privileges (token is included and authorized)
bool is_admin = false; bool is_admin = false;
EMSESP::webSettingsService.read([&](WebSettings & settings) { EMSESP::webSettingsService.read([&](WebSettings & settings) {

View File

@@ -49,7 +49,7 @@ class WebAPIService {
static uint32_t api_count_; static uint32_t api_count_;
static uint16_t api_fails_; static uint16_t api_fails_;
void parse(AsyncWebServerRequest * request, JsonObject & input); void parse(AsyncWebServerRequest * request, JsonObject input);
void getSettings(AsyncWebServerRequest * request); void getSettings(AsyncWebServerRequest * request);
void getCustomizations(AsyncWebServerRequest * request); void getCustomizations(AsyncWebServerRequest * request);

View File

@@ -42,7 +42,7 @@ void WebCustomEntityService::begin() {
// this creates the entity file, saving it to the FS // this creates the entity file, saving it to the FS
// and also calls when the Entity web page is refreshed // 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<JsonArray>(); JsonArray entity = root["entities"].to<JsonArray>();
uint8_t counter = 0; uint8_t counter = 0;
for (const CustomEntityItem & entityItem : webEntity.customEntityItems) { 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 // call on initialization and also when the Entity web page is updated
// this loads the data into the internal class // 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 #ifdef EMSESP_STANDALONE
// invoke some fake data for testing // invoke some fake data for testing
// clang-format off // clang-format off
@@ -183,7 +183,7 @@ bool WebCustomEntityService::command_setvalue(const char * value, const std::str
// output of a single value // output of a single value
// if add_uom is true it will add the UOM string to the 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]; char payload[12];
std::string name = useVal ? "value" : entity.name; std::string name = useVal ? "value" : entity.name;
switch (entity.value_type) { switch (entity.value_type) {
@@ -244,7 +244,7 @@ void WebCustomEntityService::render_value(JsonObject & output, CustomEntityItem
// display all custom entities // display all custom entities
// adding each one, with UOM to a json object string // 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) { for (const CustomEntityItem & entity : *customEntityItems) {
render_value(output, entity, false, false, true); // with add_uom 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 // 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; }); EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
if (Helpers::toLower(cmd) == F_(commands)) { if (Helpers::toLower(cmd) == F_(commands)) {
output[F_(info)] = Helpers::translated_word(FL_(info_cmd)); 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 // 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; }); EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
output["label"] = (std::string) "Custom Entities"; output["label"] = (std::string) "Custom Entities";

View File

@@ -44,8 +44,8 @@ class WebCustomEntity {
public: public:
std::list<CustomEntityItem> customEntityItems; std::list<CustomEntityItem> customEntityItems;
static void read(WebCustomEntity & webEntity, JsonObject & root); static void read(WebCustomEntity & webEntity, JsonObject root);
static StateUpdateResult update(JsonObject & root, WebCustomEntity & webEntity); static StateUpdateResult update(JsonObject root, WebCustomEntity & webEntity);
}; };
class WebCustomEntityService : public StatefulService<WebCustomEntity> { class WebCustomEntityService : public StatefulService<WebCustomEntity> {
@@ -56,12 +56,12 @@ class WebCustomEntityService : public StatefulService<WebCustomEntity> {
void publish_single(const CustomEntityItem & entity); void publish_single(const CustomEntityItem & entity);
void publish(const bool force = false); void publish(const bool force = false);
bool command_setvalue(const char * value, const std::string name); 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<const Telegram> telegram); bool get_value(std::shared_ptr<const Telegram> telegram);
void fetch(); void fetch();
void render_value(JsonObject & output, CustomEntityItem entity, const bool useVal = false, const bool web = false, const bool add_uom = false); 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 show_values(JsonObject output);
void generate_value_web(JsonObject & output); void generate_value_web(JsonObject output);
uint8_t count_entities(); uint8_t count_entities();
uint8_t has_commands(); uint8_t has_commands();

View File

@@ -55,7 +55,7 @@ WebCustomizationService::WebCustomizationService(AsyncWebServer * server, FS * f
} }
// this creates the customization file, saving it to the FS // 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 // Temperature Sensor customization
JsonArray sensorsJson = root["ts"].to<JsonArray>(); JsonArray sensorsJson = root["ts"].to<JsonArray>();
@@ -95,7 +95,7 @@ void WebCustomization::read(WebCustomization & customizations, JsonObject & root
// call on initialization and also when the page is saved via web UI // call on initialization and also when the page is saved via web UI
// this loads the data into the internal class // 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 #ifdef EMSESP_STANDALONE
// invoke some fake data for testing // invoke some fake data for testing
const char * json = "{\"ts\":[],\"as\":[],\"masked_entities\":[{\"product_id\":123,\"device_id\":8,\"entity_ids\":[\"08heatingactive|my custom " const char * json = "{\"ts\":[],\"as\":[],\"masked_entities\":[{\"product_id\":123,\"device_id\":8,\"entity_ids\":[\"08heatingactive|my custom "

View File

@@ -71,8 +71,8 @@ class WebCustomization {
std::list<SensorCustomization> sensorCustomizations; // for sensor names and offsets std::list<SensorCustomization> sensorCustomizations; // for sensor names and offsets
std::list<AnalogCustomization> analogCustomizations; // for analog sensors std::list<AnalogCustomization> analogCustomizations; // for analog sensors
std::list<EntityCustomization> entityCustomizations; // for a list of entities that have a special mask set std::list<EntityCustomization> entityCustomizations; // for a list of entities that have a special mask set
static void read(WebCustomization & customizations, JsonObject & root); static void read(WebCustomization & customizations, JsonObject root);
static StateUpdateResult update(JsonObject & root, WebCustomization & customizations); static StateUpdateResult update(JsonObject root, WebCustomization & customizations);
private: private:
static bool _start; static bool _start;

View File

@@ -36,7 +36,7 @@ void WebSchedulerService::begin() {
// this creates the scheduler file, saving it to the FS // this creates the scheduler file, saving it to the FS
// and also calls when the Scheduler web page is refreshed // 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<JsonArray>(); JsonArray schedule = root["schedule"].to<JsonArray>();
uint8_t counter = 0; uint8_t counter = 0;
for (const ScheduleItem & scheduleItem : webScheduler.scheduleItems) { 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 // call on initialization and also when the Schedule web page is saved
// this loads the data into the internal class // 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 #ifdef EMSESP_STANDALONE
// invoke some fake data for testing // invoke some fake data for testing
const char * json = 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 // 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; }); EMSESP::webSchedulerService.read([&](WebScheduler & webScheduler) { scheduleItems = &webScheduler.scheduleItems; });
if (Helpers::toLower(cmd) == F_(commands)) { if (Helpers::toLower(cmd) == F_(commands)) {
output[F_(info)] = Helpers::translated_word(FL_(info_cmd)); output[F_(info)] = Helpers::translated_word(FL_(info_cmd));

View File

@@ -43,8 +43,8 @@ class WebScheduler {
public: public:
std::list<ScheduleItem> scheduleItems; std::list<ScheduleItem> scheduleItems;
static void read(WebScheduler & webScheduler, JsonObject & root); static void read(WebScheduler & webScheduler, JsonObject root);
static StateUpdateResult update(JsonObject & root, WebScheduler & webScheduler); static StateUpdateResult update(JsonObject root, WebScheduler & webScheduler);
}; };
class WebSchedulerService : public StatefulService<WebScheduler> { class WebSchedulerService : public StatefulService<WebScheduler> {
@@ -57,7 +57,7 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
void publish(const bool force = false); void publish(const bool force = false);
bool has_commands(); bool has_commands();
bool command_setvalue(const char * value, const std::string name); 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() { void ha_reset() {
ha_registered_ = false; ha_registered_ = false;
} }

View File

@@ -35,7 +35,7 @@ WebSettingsService::WebSettingsService(AsyncWebServer * server, FS * fs, Securit
addUpdateHandler([&](const String & originId) { onUpdate(); }, false); 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["version"] = settings.version;
root["locale"] = settings.locale; root["locale"] = settings.locale;
root["tx_mode"] = settings.tx_mode; 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 // 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 // load the version of the settings
// will be picked up in System::check_upgrade() // will be picked up in System::check_upgrade()
settings.version = root["version"] | EMSESP_DEFAULT_VERSION; settings.version = root["version"] | EMSESP_DEFAULT_VERSION;

View File

@@ -71,8 +71,8 @@ class WebSettings {
uint8_t eth_phy_addr; uint8_t eth_phy_addr;
uint8_t eth_clock_mode; uint8_t eth_clock_mode;
static void read(WebSettings & settings, JsonObject & root); static void read(WebSettings & settings, JsonObject root);
static StateUpdateResult update(JsonObject & root, WebSettings & settings); static StateUpdateResult update(JsonObject root, WebSettings & settings);
enum ChangeFlags : uint8_t { enum ChangeFlags : uint8_t {