mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
remove obsolete reference to JsonObject
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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<String>() || !ip.fromString(root[key].as<String>())) {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<MqttSettings> {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<JsonObject>();
|
||||
populateJWTPayload(payload, user);
|
||||
|
||||
@@ -35,7 +35,7 @@ class SecuritySettings {
|
||||
String jwtSecret;
|
||||
std::list<User> 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<SecuritySettings>, public
|
||||
/*
|
||||
* Verify the payload is correct
|
||||
*/
|
||||
boolean validatePayload(JsonObject & parsedPayload, User * user);
|
||||
boolean validatePayload(JsonObject parsedPayload, User * user);
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
@@ -17,10 +17,10 @@ enum class StateUpdateResult {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using JsonStateUpdater = std::function<StateUpdateResult(JsonObject & root, T & settings)>;
|
||||
using JsonStateUpdater = std::function<StateUpdateResult(JsonObject root, T & settings)>;
|
||||
|
||||
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 std::function<void(const String & originId)> StateUpdateCallback;
|
||||
@@ -81,7 +81,7 @@ class StatefulService {
|
||||
return result;
|
||||
}
|
||||
|
||||
StateUpdateResult update(JsonObject & jsonObject, JsonStateUpdater<T> stateUpdater, const String & originId) {
|
||||
StateUpdateResult update(JsonObject jsonObject, JsonStateUpdater<T> stateUpdater, const String & originId) {
|
||||
beginTransaction();
|
||||
StateUpdateResult result = stateUpdater(jsonObject, _state);
|
||||
endTransaction();
|
||||
@@ -91,7 +91,7 @@ class StatefulService {
|
||||
return result;
|
||||
}
|
||||
|
||||
StateUpdateResult updateWithoutPropagation(JsonObject & jsonObject, JsonStateUpdater<T> stateUpdater) {
|
||||
StateUpdateResult updateWithoutPropagation(JsonObject jsonObject, JsonStateUpdater<T> stateUpdater) {
|
||||
beginTransaction();
|
||||
StateUpdateResult result = stateUpdater(jsonObject, _state);
|
||||
endTransaction();
|
||||
@@ -104,7 +104,7 @@ class StatefulService {
|
||||
endTransaction();
|
||||
}
|
||||
|
||||
void read(JsonObject & jsonObject, JsonStateReader<T> stateReader) {
|
||||
void read(JsonObject jsonObject, JsonStateReader<T> stateReader) {
|
||||
beginTransaction();
|
||||
stateReader(_state, jsonObject);
|
||||
endTransaction();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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<JsonObject>();
|
||||
populateJWTPayload(payload, user);
|
||||
|
||||
@@ -32,7 +32,7 @@ class SecuritySettings {
|
||||
String jwtSecret;
|
||||
std::list<User> 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<SecuritySettings>, public
|
||||
|
||||
void configureJWTHandler();
|
||||
Authentication authenticateJWT(String & jwt);
|
||||
boolean validatePayload(JsonObject & parsedPayload, User * user);
|
||||
boolean validatePayload(JsonObject parsedPayload, User * user);
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
@@ -15,10 +15,10 @@ enum class StateUpdateResult {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using JsonStateUpdater = std::function<StateUpdateResult(JsonObject & root, T & settings)>;
|
||||
using JsonStateUpdater = std::function<StateUpdateResult(JsonObject root, T & settings)>;
|
||||
|
||||
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 std::function<void(const String & originId)> StateUpdateCallback;
|
||||
@@ -85,7 +85,7 @@ class StatefulService {
|
||||
return result;
|
||||
}
|
||||
|
||||
StateUpdateResult update(JsonObject & jsonObject, JsonStateUpdater<T> stateUpdater, const String & originId) {
|
||||
StateUpdateResult update(JsonObject jsonObject, JsonStateUpdater<T> stateUpdater, const String & originId) {
|
||||
beginTransaction();
|
||||
StateUpdateResult result = stateUpdater(jsonObject, _state);
|
||||
endTransaction();
|
||||
@@ -95,7 +95,7 @@ class StatefulService {
|
||||
return result;
|
||||
}
|
||||
|
||||
StateUpdateResult updateWithoutPropagation(JsonObject & jsonObject, JsonStateUpdater<T> stateUpdater) {
|
||||
StateUpdateResult updateWithoutPropagation(JsonObject jsonObject, JsonStateUpdater<T> stateUpdater) {
|
||||
beginTransaction();
|
||||
StateUpdateResult result = stateUpdater(jsonObject, _state);
|
||||
endTransaction();
|
||||
@@ -108,7 +108,7 @@ class StatefulService {
|
||||
endTransaction();
|
||||
}
|
||||
|
||||
void read(JsonObject & jsonObject, JsonStateReader<T> stateReader) {
|
||||
void read(JsonObject jsonObject, JsonStateReader<T> stateReader) {
|
||||
beginTransaction();
|
||||
stateReader(_state, jsonObject);
|
||||
endTransaction();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Sensor> sensors_; // our list of sensors
|
||||
|
||||
|
||||
@@ -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 entry point will be either via the Web API (api/) or MQTT (<base>/)
|
||||
// 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;
|
||||
|
||||
@@ -49,7 +49,7 @@ enum CommandRet : uint8_t {
|
||||
};
|
||||
|
||||
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 {
|
||||
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<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["message"] = message;
|
||||
return error_code;
|
||||
|
||||
@@ -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<JsonArray>();
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -662,7 +662,7 @@ void EMSESP::publish_response(std::shared_ptr<const Telegram> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<const Telegram> telegram);
|
||||
static void publish_response(std::shared_ptr<const Telegram> 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
|
||||
|
||||
40
src/mqtt.cpp
40
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;
|
||||
|
||||
40
src/mqtt.h
40
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);
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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<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
|
||||
// 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
|
||||
|
||||
14
src/system.h
14
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<int8_t> & data, const std::string & board_profile);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<Sensor> 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<Sensor> sensors_; // our list of active sensors
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<JsonArray>();
|
||||
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";
|
||||
|
||||
@@ -44,8 +44,8 @@ class WebCustomEntity {
|
||||
public:
|
||||
std::list<CustomEntityItem> 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<WebCustomEntity> {
|
||||
@@ -56,12 +56,12 @@ class WebCustomEntityService : public StatefulService<WebCustomEntity> {
|
||||
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<const Telegram> 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();
|
||||
|
||||
@@ -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<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
|
||||
// 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 "
|
||||
|
||||
@@ -71,8 +71,8 @@ class WebCustomization {
|
||||
std::list<SensorCustomization> sensorCustomizations; // for sensor names and offsets
|
||||
std::list<AnalogCustomization> analogCustomizations; // for analog sensors
|
||||
std::list<EntityCustomization> 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;
|
||||
|
||||
@@ -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<JsonArray>();
|
||||
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));
|
||||
|
||||
@@ -43,8 +43,8 @@ class WebScheduler {
|
||||
public:
|
||||
std::list<ScheduleItem> 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<WebScheduler> {
|
||||
@@ -57,7 +57,7 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user