mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Add jsonl pseudo-attribute
This commit is contained in:
parent
d59bde5d9c
commit
c3b10fd2c8
@ -1375,6 +1375,47 @@ static hasp_attribute_type_t attribute_common_tag(lv_obj_t* obj, uint16_t attr_h
|
|||||||
|
|
||||||
return HASP_ATTR_TYPE_JSON;
|
return HASP_ATTR_TYPE_JSON;
|
||||||
}
|
}
|
||||||
|
static hasp_attribute_type_t attribute_common_json(lv_obj_t* obj, uint16_t attr_hash, const char* payload, char** text,
|
||||||
|
bool update)
|
||||||
|
{
|
||||||
|
switch(attr_hash) {
|
||||||
|
case ATTR_JSONL:
|
||||||
|
if(update) {
|
||||||
|
|
||||||
|
size_t maxsize = (512u + JSON_OBJECT_SIZE(25));
|
||||||
|
DynamicJsonDocument json(maxsize);
|
||||||
|
|
||||||
|
// Note: Deserialization can to be (char *) so the objects WILL NOT be copied
|
||||||
|
// this uses less memory since the data is already copied from the mqtt receive buffer and cannot get
|
||||||
|
// overwritten by the send buffer !!
|
||||||
|
DeserializationError jsonError = deserializeJson(json, (char*)payload);
|
||||||
|
json.shrinkToFit();
|
||||||
|
|
||||||
|
if(!jsonError) {
|
||||||
|
// Make sure we have a valid JsonObject to start from
|
||||||
|
if(JsonObject keys = json.as<JsonObject>()) {
|
||||||
|
hasp_parse_json_attributes(obj, keys); // json is valid object, cast as a JsonObject
|
||||||
|
} else {
|
||||||
|
jsonError = DeserializationError::InvalidInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(jsonError) { // Couldn't parse incoming JSON object
|
||||||
|
dispatch_json_error(TAG_ATTR, jsonError);
|
||||||
|
return HASP_ATTR_TYPE_METHOD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return HASP_ATTR_TYPE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
break; // attribute_found
|
||||||
|
|
||||||
|
default:
|
||||||
|
return HASP_ATTR_TYPE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HASP_ATTR_TYPE_METHOD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static hasp_attribute_type_t attribute_common_text(lv_obj_t* obj, const char* attr, const char* payload, char** text,
|
static hasp_attribute_type_t attribute_common_text(lv_obj_t* obj, const char* attr, const char* payload, char** text,
|
||||||
bool update)
|
bool update)
|
||||||
@ -2322,6 +2363,9 @@ void hasp_process_obj_attribute(lv_obj_t* obj, const char* attribute, const char
|
|||||||
case ATTR_TAG:
|
case ATTR_TAG:
|
||||||
ret = attribute_common_tag(obj, attr_hash, payload, &text, update);
|
ret = attribute_common_tag(obj, attr_hash, payload, &text, update);
|
||||||
break;
|
break;
|
||||||
|
case ATTR_JSONL:
|
||||||
|
ret = attribute_common_json(obj, attr_hash, payload, &text, update);
|
||||||
|
break;
|
||||||
|
|
||||||
case ATTR_OBJ:
|
case ATTR_OBJ:
|
||||||
text = (char*)obj_get_type_name(obj);
|
text = (char*)obj_get_type_name(obj);
|
||||||
|
@ -424,6 +424,7 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t)
|
|||||||
#define ATTR_START_VALUE 11828
|
#define ATTR_START_VALUE 11828
|
||||||
#define ATTR_COMMENT 62559
|
#define ATTR_COMMENT 62559
|
||||||
#define ATTR_TAG 7866
|
#define ATTR_TAG 7866
|
||||||
|
#define ATTR_JSONL 61604
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
#define ATTR_DELETE 50027
|
#define ATTR_DELETE 50027
|
||||||
|
@ -174,14 +174,13 @@ void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, con
|
|||||||
|
|
||||||
// ##################### Object Creator ########################################################
|
// ##################### Object Creator ########################################################
|
||||||
|
|
||||||
// Called from hasp_new_object only to process all attributes
|
// Called from hasp_new_object or TAG_JSON to process all attributes
|
||||||
static inline int hasp_parse_json_attributes(lv_obj_t* obj, const JsonObject& doc)
|
int hasp_parse_json_attributes(lv_obj_t* obj, const JsonObject& doc)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
#if defined(WINDOWS) || defined(POSIX)
|
#if defined(WINDOWS) || defined(POSIX) || defined(ESP32)
|
||||||
// String v((char *)0);
|
|
||||||
// v.reserve(64);
|
|
||||||
std::string v;
|
std::string v;
|
||||||
|
v.reserve(64);
|
||||||
|
|
||||||
for(JsonPair keyValue : doc) {
|
for(JsonPair keyValue : doc) {
|
||||||
// LOG_VERBOSE(TAG_HASP, F(D_BULLET "%s=%s"), keyValue.key().c_str(),
|
// LOG_VERBOSE(TAG_HASP, F(D_BULLET "%s=%s"), keyValue.key().c_str(),
|
||||||
|
@ -90,6 +90,7 @@ void hasp_object_tree(const lv_obj_t* parent, uint8_t pageid, uint16_t level);
|
|||||||
void object_dispatch_state(uint8_t pageid, uint8_t btnid, const char* payload);
|
void object_dispatch_state(uint8_t pageid, uint8_t btnid, const char* payload);
|
||||||
|
|
||||||
void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, const char* payload, bool update);
|
void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, const char* payload, bool update);
|
||||||
|
int hasp_parse_json_attributes(lv_obj_t* obj, const JsonObject& doc);
|
||||||
|
|
||||||
void object_set_normalized_group_values(hasp_update_value_t& value);
|
void object_set_normalized_group_values(hasp_update_value_t& value);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user