mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Allow updating a text attribute with empty string
This commit is contained in:
parent
b414e23601
commit
90a6299279
@ -116,7 +116,7 @@ void dispatch_output_pin_value(uint8_t pin, uint16_t val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// p[x].b[y].attr=value
|
// p[x].b[y].attr=value
|
||||||
static inline bool dispatch_parse_button_attribute(const char* topic_p, const char* payload)
|
static inline bool dispatch_parse_button_attribute(const char* topic_p, const char* payload, bool update)
|
||||||
{
|
{
|
||||||
long num;
|
long num;
|
||||||
char* pEnd;
|
char* pEnd;
|
||||||
@ -161,7 +161,7 @@ static inline bool dispatch_parse_button_attribute(const char* topic_p, const ch
|
|||||||
if(*topic_p != '.') return false; // obligated seperator
|
if(*topic_p != '.') return false; // obligated seperator
|
||||||
topic_p++;
|
topic_p++;
|
||||||
|
|
||||||
hasp_process_attribute(pageid, objid, topic_p, payload);
|
hasp_process_attribute(pageid, objid, topic_p, payload, update);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,11 +197,11 @@ static void dispatch_gpio(const char* topic, const char* payload)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// objectattribute=value
|
// objectattribute=value
|
||||||
void dispatch_command(const char* topic, const char* payload)
|
void dispatch_command(const char* topic, const char* payload, bool update)
|
||||||
{
|
{
|
||||||
/* ================================= Standard payload commands ======================================= */
|
/* ================================= Standard payload commands ======================================= */
|
||||||
|
|
||||||
if(dispatch_parse_button_attribute(topic, payload)) return; // matched pxby.attr, first for speed
|
if(dispatch_parse_button_attribute(topic, payload, update)) return; // matched pxby.attr, first for speed
|
||||||
|
|
||||||
// check and execute commands from commands array
|
// check and execute commands from commands array
|
||||||
for(int i = 0; i < nCommands; i++) {
|
for(int i = 0; i < nCommands; i++) {
|
||||||
@ -254,16 +254,16 @@ void dispatch_command(const char* topic, const char* payload)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Strip command/config prefix from the topic and process the payload
|
// Strip command/config prefix from the topic and process the payload
|
||||||
void dispatch_topic_payload(const char* topic, const char* payload)
|
void dispatch_topic_payload(const char* topic, const char* payload, bool update)
|
||||||
{
|
{
|
||||||
if(!strcmp_P(topic, PSTR("command"))) {
|
if(!strcmp_P(topic, PSTR(HASP_TOPIC_COMMAND))) {
|
||||||
dispatch_text_line((char*)payload);
|
dispatch_text_line((char*)payload);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(topic == strstr_P(topic, PSTR("command/"))) { // startsWith command/
|
if(topic == strstr_P(topic, PSTR(HASP_TOPIC_COMMAND "/"))) { // startsWith command/
|
||||||
topic += 8u;
|
topic += 8u;
|
||||||
dispatch_command(topic, (char*)payload);
|
dispatch_command(topic, (char*)payload, update);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +275,7 @@ void dispatch_topic_payload(const char* topic, const char* payload)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dispatch_command(topic, (char*)payload); // dispatch as is
|
dispatch_command(topic, (char*)payload, update); // dispatch as is
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse one line of text and execute the command
|
// Parse one line of text and execute the command
|
||||||
@ -284,14 +284,16 @@ void dispatch_text_line(const char* cmnd)
|
|||||||
size_t pos1 = std::string(cmnd).find("=");
|
size_t pos1 = std::string(cmnd).find("=");
|
||||||
size_t pos2 = std::string(cmnd).find(" ");
|
size_t pos2 = std::string(cmnd).find(" ");
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
|
bool update = false;
|
||||||
|
|
||||||
// Find what comes first, ' ' or '='
|
// Find what comes first, ' ' or '='
|
||||||
if(pos1 != std::string::npos) {
|
if(pos1 != std::string::npos) { // '=' found
|
||||||
if(pos2 != std::string::npos) {
|
if(pos2 != std::string::npos) { // ' ' found
|
||||||
pos = (pos1 < pos2 ? pos1 : pos2);
|
pos = (pos1 < pos2 ? pos1 : pos2);
|
||||||
} else {
|
} else {
|
||||||
pos = pos1;
|
pos = pos1;
|
||||||
}
|
}
|
||||||
|
update = pos == pos1; // equal sign wins
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
pos = (pos2 != std::string::npos) ? pos2 : 0;
|
pos = (pos2 != std::string::npos) ? pos2 : 0;
|
||||||
@ -306,12 +308,13 @@ void dispatch_text_line(const char* cmnd)
|
|||||||
memcpy(topic, cmnd, sizeof(topic) - 1);
|
memcpy(topic, cmnd, sizeof(topic) - 1);
|
||||||
|
|
||||||
// topic is before '=', payload is after '=' position
|
// topic is before '=', payload is after '=' position
|
||||||
LOG_TRACE(TAG_MSGR, F("%s=%s"), topic, cmnd + pos + 1);
|
update |= strlen(cmnd + pos + 1) > 0; // equal sign OR space with payload
|
||||||
dispatch_topic_payload(topic, cmnd + pos + 1);
|
LOG_TRACE(TAG_MSGR, update ? F("%s=%s") : F("%s%s"), topic, cmnd + pos + 1);
|
||||||
|
dispatch_topic_payload(topic, cmnd + pos + 1, update);
|
||||||
} else {
|
} else {
|
||||||
char empty_payload[1] = {0};
|
char empty_payload[1] = {0};
|
||||||
LOG_TRACE(TAG_MSGR, F("%s=%s"), cmnd, empty_payload);
|
LOG_TRACE(TAG_MSGR, cmnd);
|
||||||
dispatch_topic_payload(cmnd, empty_payload);
|
dispatch_topic_payload(cmnd, empty_payload, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ void dispatchStart(void);
|
|||||||
void dispatchStop(void);
|
void dispatchStop(void);
|
||||||
|
|
||||||
/* ===== Special Event Processors ===== */
|
/* ===== Special Event Processors ===== */
|
||||||
void dispatch_topic_payload(const char* topic, const char* payload);
|
void dispatch_topic_payload(const char* topic, const char* payload, bool update);
|
||||||
void dispatch_text_line(const char* cmnd);
|
void dispatch_text_line(const char* cmnd);
|
||||||
|
|
||||||
#ifdef ARDUINO
|
#ifdef ARDUINO
|
||||||
@ -56,6 +56,7 @@ void dispatch_current_page();
|
|||||||
void dispatch_backlight(const char*, const char* payload);
|
void dispatch_backlight(const char*, const char* payload);
|
||||||
void dispatch_web_update(const char*, const char* espOtaUrl);
|
void dispatch_web_update(const char*, const char* espOtaUrl);
|
||||||
void dispatch_statusupdate(const char*, const char*);
|
void dispatch_statusupdate(const char*, const char*);
|
||||||
|
void dispatch_send_discovery(const char*, const char*);
|
||||||
void dispatch_idle(const char*, const char*);
|
void dispatch_idle(const char*, const char*);
|
||||||
void dispatch_calibrate(const char*, const char*);
|
void dispatch_calibrate(const char*, const char*);
|
||||||
void dispatch_wakeup(const char*, const char*);
|
void dispatch_wakeup(const char*, const char*);
|
||||||
|
@ -285,10 +285,10 @@ void object_set_normalized_group_values(uint8_t groupid, lv_obj_t* src_obj, int1
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Used in the dispatcher & hasp_new_object
|
// Used in the dispatcher & hasp_new_object
|
||||||
void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, const char* payload)
|
void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, const char* payload, bool update)
|
||||||
{
|
{
|
||||||
if(lv_obj_t* obj = hasp_find_obj_from_parent_id(haspPages.get_obj(pageid), objid)) {
|
if(lv_obj_t* obj = hasp_find_obj_from_parent_id(haspPages.get_obj(pageid), objid)) {
|
||||||
hasp_process_obj_attribute(obj, attr, payload, strlen(payload) > 0);
|
hasp_process_obj_attribute(obj, attr, payload, update); // || strlen(payload) > 0);
|
||||||
} else {
|
} else {
|
||||||
LOG_WARNING(TAG_HASP, F(D_OBJECT_UNKNOWN " " HASP_OBJECT_NOTATION), pageid, objid);
|
LOG_WARNING(TAG_HASP, F(D_OBJECT_UNKNOWN " " HASP_OBJECT_NOTATION), pageid, objid);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ void hasp_object_tree(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);
|
void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char* attr, const char* payload, bool update);
|
||||||
|
|
||||||
void object_set_normalized_group_values(uint8_t groupid, lv_obj_t* src_obj, int16_t val, int16_t min, int16_t max);
|
void object_set_normalized_group_values(uint8_t groupid, lv_obj_t* src_obj, int16_t val, int16_t min, int16_t max);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user