mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
ArduinoJson 7.2 upgrade
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
|||||||
Version 7.1.0
|
Version 7.2.0
|
||||||
|
|
||||||
From https://github.com/bblanchon/ArduinoJson/releases
|
From https://github.com/bblanchon/ArduinoJson/releases
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
|||||||
const char * device_s = nullptr;
|
const char * device_s = nullptr;
|
||||||
if (!num_paths) {
|
if (!num_paths) {
|
||||||
// we must look for the device in the JSON body
|
// we must look for the device in the JSON body
|
||||||
if (input.containsKey("device")) {
|
if (input["device"].is<const char *>()) {
|
||||||
device_s = input["device"];
|
device_s = input["device"];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -89,9 +89,9 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
|||||||
command_p = command;
|
command_p = command;
|
||||||
} else {
|
} else {
|
||||||
// take it from the JSON
|
// take it from the JSON
|
||||||
if (input.containsKey("entity")) {
|
if (input["entity"].is<const char *>()) {
|
||||||
command_p = input["entity"];
|
command_p = input["entity"];
|
||||||
} else if (input.containsKey("cmd")) {
|
} else if (input["cmd"].is<const char *>()) {
|
||||||
command_p = input["cmd"];
|
command_p = input["cmd"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,20 +111,20 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we don't have an id/hc/dhw try and get it from the JSON input
|
// if we don't have an id/hc/dhw try and get it from the JSON input. It must be a number.
|
||||||
// it's allowed to have no id, and then keep the default to -1
|
// it's allowed to have no id, and then keep the default to -1
|
||||||
if (id_n == -1) {
|
if (id_n == -1) {
|
||||||
if (input.containsKey("hc")) {
|
if (input["hc"].is<int>()) {
|
||||||
id_n = input["hc"];
|
id_n = input["hc"];
|
||||||
} else if (input.containsKey("dhw")) {
|
} else if (input["dhw"].is<int>()) {
|
||||||
id_n = input["dhw"];
|
id_n = input["dhw"];
|
||||||
id_n += DeviceValueTAG::TAG_DHW1 - DeviceValueTAG::TAG_HC1; // dhw1 has id 9
|
id_n += DeviceValueTAG::TAG_DHW1 - DeviceValueTAG::TAG_HC1; // dhw1 has id 9
|
||||||
} else if (input.containsKey("id")) {
|
} else if (input["id"].is<int>()) {
|
||||||
id_n = input["id"];
|
id_n = input["id"];
|
||||||
} else if (input.containsKey("ahs")) {
|
} else if (input["ahs"].is<int>()) {
|
||||||
id_n = input["ahs"];
|
id_n = input["ahs"];
|
||||||
id_n += DeviceValueTAG::TAG_AHS1 - DeviceValueTAG::TAG_HC1; // ahs1 has id 19
|
id_n += DeviceValueTAG::TAG_AHS1 - DeviceValueTAG::TAG_HC1; // ahs1 has id 19
|
||||||
} else if (input.containsKey("hs")) {
|
} else if (input["hs"].is<int>()) {
|
||||||
id_n = input["hs"];
|
id_n = input["hs"];
|
||||||
id_n += DeviceValueTAG::TAG_HS1 - DeviceValueTAG::TAG_HC1; // hs1 has id 20
|
id_n += DeviceValueTAG::TAG_HS1 - DeviceValueTAG::TAG_HC1; // hs1 has id 20
|
||||||
}
|
}
|
||||||
@@ -132,9 +132,9 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
|||||||
|
|
||||||
// the value must always come from the input JSON. It's allowed to be empty.
|
// the value must always come from the input JSON. It's allowed to be empty.
|
||||||
JsonVariant data;
|
JsonVariant data;
|
||||||
if (input.containsKey("data")) {
|
if (input["data"].is<JsonVariantConst>()) {
|
||||||
data = input["data"];
|
data = input["data"];
|
||||||
} else if (input.containsKey("value")) {
|
} else if (input["value"].is<JsonVariantConst>()) {
|
||||||
data = input["value"];
|
data = input["value"];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,8 +298,8 @@ bool Command::set_attribute(JsonObject output, const char * cmd, const char * at
|
|||||||
if (attribute == nullptr) {
|
if (attribute == nullptr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (output.containsKey(attribute)) {
|
if (output[attribute].is<std::string>()) {
|
||||||
std::string data = output[attribute].as<std::string>();
|
std::string data = output[attribute];
|
||||||
output.clear();
|
output.clear();
|
||||||
output["api_data"] = data; // always as a string
|
output["api_data"] = data; // always as a string
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -552,8 +552,8 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
|||||||
|
|
||||||
if (return_code == CommandRet::OK) {
|
if (return_code == CommandRet::OK) {
|
||||||
if (json.size()) {
|
if (json.size()) {
|
||||||
if (json.containsKey("api_data")) {
|
if (json["api_data"].is<String>()) {
|
||||||
String data = json["api_data"].as<String>();
|
String data = json["api_data"];
|
||||||
shell.println(data.c_str());
|
shell.println(data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3250,11 +3250,11 @@ bool Thermostat::set_switchtime(const char * value, const uint16_t type_id, char
|
|||||||
if (error) {
|
if (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!doc.containsKey("no")) {
|
if (!doc["no"].is<int>()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
no = doc["no"].as<int>();
|
no = doc["no"];
|
||||||
if (!doc.containsKey("day") || !doc.containsKey("mode") || !doc.containsKey("time")) {
|
if (!doc["day"].is<const char *>() || !doc["mode"].is<const char *>() || !doc["time"].is<const char *>()) {
|
||||||
EMSESP::wait_validate(type_id);
|
EMSESP::wait_validate(type_id);
|
||||||
read_command(type_id, 2 * no, 2);
|
read_command(type_id, 2 * no, 2);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1681,7 +1681,7 @@ bool EMSdevice::generate_values(JsonObject output, const int8_t tag_filter, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do not overwrite
|
// do not overwrite
|
||||||
if (json.containsKey(name)) {
|
if (json[name].is<const char *>()) {
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_DEBUG)
|
||||||
EMSESP::logger().debug("warning: double json key: %s", name);
|
EMSESP::logger().debug("warning: double json key: %s", name);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ void Mqtt::on_message(const char * topic, const uint8_t * payload, size_t len) {
|
|||||||
// if the payload doesn't not contain the key 'value' or 'data', treat the whole payload as the 'value'
|
// if the payload doesn't not contain the key 'value' or 'data', treat the whole payload as the 'value'
|
||||||
if (len != 0) {
|
if (len != 0) {
|
||||||
DeserializationError error = deserializeJson(input_doc, (const char *)message);
|
DeserializationError error = deserializeJson(input_doc, (const char *)message);
|
||||||
if ((!input_doc.containsKey("value") && !input_doc.containsKey("data")) || error) {
|
if (((!input_doc["value"].is<JsonVariantConst>()) && (!input_doc["data"].is<JsonVariantConst>())) || error) {
|
||||||
input_doc.clear();
|
input_doc.clear();
|
||||||
input_doc["value"] = (const char *)message; // always a string
|
input_doc["value"] = (const char *)message; // always a string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -360,8 +360,8 @@ std::string commands(std::string & expr, bool quotes = true) {
|
|||||||
JsonObject input = doc_in.to<JsonObject>();
|
JsonObject input = doc_in.to<JsonObject>();
|
||||||
std::string cmd_s = "api/" + std::string(cmd);
|
std::string cmd_s = "api/" + std::string(cmd);
|
||||||
emsesp::Command::process(cmd_s.c_str(), true, input, output);
|
emsesp::Command::process(cmd_s.c_str(), true, input, output);
|
||||||
if (output.containsKey("api_data")) {
|
if (output["api_data"].is<std::string>()) {
|
||||||
std::string data = output["api_data"].as<std::string>();
|
std::string data = output["api_data"];
|
||||||
if (!isnum(data) && quotes) {
|
if (!isnum(data) && quotes) {
|
||||||
data.insert(data.begin(), '"');
|
data.insert(data.begin(), '"');
|
||||||
data.insert(data.end(), '"');
|
data.insert(data.end(), '"');
|
||||||
|
|||||||
@@ -789,7 +789,6 @@ void System::network_init(bool refresh) {
|
|||||||
auto clock_mode = (eth_clock_mode_t)eth_clock_mode_;
|
auto clock_mode = (eth_clock_mode_t)eth_clock_mode_;
|
||||||
|
|
||||||
// reset power and add a delay as ETH doesn't not always start up correctly after a warm boot
|
// reset power and add a delay as ETH doesn't not always start up correctly after a warm boot
|
||||||
// TODO still experimental
|
|
||||||
if (eth_power_ != -1) {
|
if (eth_power_ != -1) {
|
||||||
pinMode(eth_power_, OUTPUT);
|
pinMode(eth_power_, OUTPUT);
|
||||||
digitalWrite(eth_power_, LOW);
|
digitalWrite(eth_power_, LOW);
|
||||||
|
|||||||
@@ -126,20 +126,20 @@ StateUpdateResult WebCustomEntity::update(JsonObject root, WebCustomEntity & web
|
|||||||
|
|
||||||
webCustomEntity.customEntityItems.push_back(entityItem); // add to list
|
webCustomEntity.customEntityItems.push_back(entityItem); // add to list
|
||||||
|
|
||||||
if (webCustomEntity.customEntityItems.back().writeable && !webCustomEntity.customEntityItems.back().name.empty()) {
|
if (entityItem.writeable && !entityItem.name.empty()) {
|
||||||
Command::add(
|
Command::add(
|
||||||
EMSdevice::DeviceType::CUSTOM,
|
EMSdevice::DeviceType::CUSTOM,
|
||||||
webCustomEntity.customEntityItems.back().name.c_str(),
|
entityItem.name.c_str(),
|
||||||
[webCustomEntity](const char * value, const int8_t id) {
|
[entityItem](const char * value, const int8_t id) {
|
||||||
return EMSESP::webCustomEntityService.command_setvalue(value, id, webCustomEntity.customEntityItems.back().name.c_str());
|
return EMSESP::webCustomEntityService.command_setvalue(value, id, entityItem.name.c_str());
|
||||||
},
|
},
|
||||||
FL_(entity_cmd),
|
FL_(entity_cmd),
|
||||||
CommandFlag::ADMIN_ONLY);
|
CommandFlag::ADMIN_ONLY);
|
||||||
}
|
}
|
||||||
if (webCustomEntity.customEntityItems.back().ram && doc.containsKey(webCustomEntity.customEntityItems.back().name)
|
|
||||||
&& doc[webCustomEntity.customEntityItems.back().name] != webCustomEntity.customEntityItems.back().value) {
|
if (entityItem.ram && doc[entityItem.name].is<JsonVariantConst>() && doc[entityItem.name] != entityItem.value) {
|
||||||
char cmd[COMMAND_MAX_LENGTH];
|
char cmd[COMMAND_MAX_LENGTH];
|
||||||
snprintf(cmd, sizeof(cmd), "%s/%s", F_(custom), webCustomEntity.customEntityItems.back().name.c_str());
|
snprintf(cmd, sizeof(cmd), "%s/%s", F_(custom), entityItem.name.c_str());
|
||||||
EMSESP::webSchedulerService.onChange(cmd);
|
EMSESP::webSchedulerService.onChange(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -462,7 +462,10 @@ uint8_t WebCustomEntityService::count_entities() {
|
|||||||
uint8_t count = 0;
|
uint8_t count = 0;
|
||||||
for (const CustomEntityItem & entity : *customEntityItems_) {
|
for (const CustomEntityItem & entity : *customEntityItems_) {
|
||||||
render_value(output, entity);
|
render_value(output, entity);
|
||||||
count += (output.containsKey(entity.name) || entity.writeable) ? 1 : 0;
|
// TODO check JsonVariant
|
||||||
|
if (output[entity.name].is<JsonVariantConst>() || entity.writeable) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
@@ -479,15 +482,18 @@ 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) {
|
||||||
// output["label"] = (std::string) "Custom Entities";
|
|
||||||
JsonArray data = output["data"].to<JsonArray>();
|
JsonArray data = output["data"].to<JsonArray>();
|
||||||
uint8_t index = 0;
|
uint8_t index = 0;
|
||||||
|
|
||||||
for (const CustomEntityItem & entity : *customEntityItems_) {
|
for (const CustomEntityItem & entity : *customEntityItems_) {
|
||||||
JsonObject obj = data.add<JsonObject>(); // create the object, we know there is a value
|
bool include = false;
|
||||||
obj["id"] = "00" + entity.name;
|
JsonObject obj = data.add<JsonObject>(); // create the object, we know there is a value
|
||||||
obj["u"] = entity.uom;
|
obj["id"] = "00" + entity.name;
|
||||||
|
obj["u"] = entity.uom;
|
||||||
|
|
||||||
if (entity.writeable) {
|
if (entity.writeable) {
|
||||||
obj["c"] = entity.name;
|
obj["c"] = entity.name;
|
||||||
|
include = true;
|
||||||
if (entity.value_type != DeviceValueType::BOOL && entity.value_type != DeviceValueType::STRING) {
|
if (entity.value_type != DeviceValueType::BOOL && entity.value_type != DeviceValueType::STRING) {
|
||||||
char s[10];
|
char s[10];
|
||||||
obj["s"] = Helpers::render_value(s, entity.factor, 1);
|
obj["s"] = Helpers::render_value(s, entity.factor, 1);
|
||||||
@@ -497,7 +503,9 @@ void WebCustomEntityService::generate_value_web(JsonObject output) {
|
|||||||
switch (entity.value_type) {
|
switch (entity.value_type) {
|
||||||
case DeviceValueType::BOOL: {
|
case DeviceValueType::BOOL: {
|
||||||
char s[12];
|
char s[12];
|
||||||
obj["v"] = Helpers::render_boolean(s, (uint8_t)entity.value, true);
|
obj["v"] = Helpers::render_boolean(s, (uint8_t)entity.value, true);
|
||||||
|
include = true;
|
||||||
|
|
||||||
JsonArray l = obj["l"].to<JsonArray>();
|
JsonArray l = obj["l"].to<JsonArray>();
|
||||||
l.add(Helpers::render_boolean(s, false, true));
|
l.add(Helpers::render_boolean(s, false, true));
|
||||||
l.add(Helpers::render_boolean(s, true, true));
|
l.add(Helpers::render_boolean(s, true, true));
|
||||||
@@ -506,21 +514,25 @@ void WebCustomEntityService::generate_value_web(JsonObject output) {
|
|||||||
case DeviceValueType::INT8:
|
case DeviceValueType::INT8:
|
||||||
if ((int8_t)entity.value != EMS_VALUE_INT8_NOTSET) {
|
if ((int8_t)entity.value != EMS_VALUE_INT8_NOTSET) {
|
||||||
obj["v"] = Helpers::transformNumFloat(entity.factor * (int8_t)entity.value, 0);
|
obj["v"] = Helpers::transformNumFloat(entity.factor * (int8_t)entity.value, 0);
|
||||||
|
include = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DeviceValueType::UINT8:
|
case DeviceValueType::UINT8:
|
||||||
if ((uint8_t)entity.value != EMS_VALUE_UINT8_NOTSET) {
|
if ((uint8_t)entity.value != EMS_VALUE_UINT8_NOTSET) {
|
||||||
obj["v"] = Helpers::transformNumFloat(entity.factor * (uint8_t)entity.value, 0);
|
obj["v"] = Helpers::transformNumFloat(entity.factor * (uint8_t)entity.value, 0);
|
||||||
|
include = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DeviceValueType::INT16:
|
case DeviceValueType::INT16:
|
||||||
if ((int16_t)entity.value != EMS_VALUE_INT16_NOTSET) {
|
if ((int16_t)entity.value != EMS_VALUE_INT16_NOTSET) {
|
||||||
obj["v"] = Helpers::transformNumFloat(entity.factor * (int16_t)entity.value, 0);
|
obj["v"] = Helpers::transformNumFloat(entity.factor * (int16_t)entity.value, 0);
|
||||||
|
include = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DeviceValueType::UINT16:
|
case DeviceValueType::UINT16:
|
||||||
if ((uint16_t)entity.value != EMS_VALUE_UINT16_NOTSET) {
|
if ((uint16_t)entity.value != EMS_VALUE_UINT16_NOTSET) {
|
||||||
obj["v"] = Helpers::transformNumFloat(entity.factor * (uint16_t)entity.value, 0);
|
obj["v"] = Helpers::transformNumFloat(entity.factor * (uint16_t)entity.value, 0);
|
||||||
|
include = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DeviceValueType::UINT24:
|
case DeviceValueType::UINT24:
|
||||||
@@ -528,11 +540,13 @@ void WebCustomEntityService::generate_value_web(JsonObject output) {
|
|||||||
case DeviceValueType::UINT32:
|
case DeviceValueType::UINT32:
|
||||||
if (entity.value != EMS_VALUE_UINT24_NOTSET) {
|
if (entity.value != EMS_VALUE_UINT24_NOTSET) {
|
||||||
obj["v"] = Helpers::transformNumFloat(entity.factor * entity.value, 0);
|
obj["v"] = Helpers::transformNumFloat(entity.factor * entity.value, 0);
|
||||||
|
include = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DeviceValueType::STRING:
|
case DeviceValueType::STRING:
|
||||||
if (entity.data.length() > 0) {
|
if (entity.data.length() > 0) {
|
||||||
obj["v"] = entity.data;
|
obj["v"] = entity.data;
|
||||||
|
include = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -540,10 +554,10 @@ void WebCustomEntityService::generate_value_web(JsonObject output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// show only entities with value or command
|
// show only entities with value or command
|
||||||
if (!obj.containsKey("v") && !obj.containsKey("c")) {
|
if (include) {
|
||||||
data.remove(index);
|
|
||||||
} else {
|
|
||||||
index++;
|
index++;
|
||||||
|
} else {
|
||||||
|
data.remove(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ void WebSchedulerService::publish(const bool force) {
|
|||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
bool ha_created = ha_registered_;
|
bool ha_created = ha_registered_;
|
||||||
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
|
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
|
||||||
if (!scheduleItem.name.empty() && !doc.containsKey(scheduleItem.name)) {
|
if (!scheduleItem.name.empty() && !doc[scheduleItem.name].is<const char *>()) {
|
||||||
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
|
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
|
||||||
doc[scheduleItem.name] = scheduleItem.active;
|
doc[scheduleItem.name] = scheduleItem.active;
|
||||||
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
|
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
|
||||||
|
|||||||
Reference in New Issue
Block a user