First start of MQTT buttons
This commit is contained in:
18
src/widget.c
18
src/widget.c
@ -81,6 +81,8 @@ struct widget_t *widget_create_from_json(const char *json) {
|
||||
widget->type=type;
|
||||
widget->label=label;
|
||||
widget->img=img;
|
||||
|
||||
// Load widget-specific attributes
|
||||
if (type == WIDGET_TYPE_LOADSCREEN) {
|
||||
if (json_scanf(json, strlen(json), "{screen:%Q}", &screen) != 1) {
|
||||
LOG(LL_WARN, ("Widget '%s' is of type LOADSCREEN but does not have attribute 'screen'", widget->name));
|
||||
@ -88,6 +90,22 @@ struct widget_t *widget_create_from_json(const char *json) {
|
||||
if (widget->user_data) free(widget->user_data);
|
||||
widget->user_data = screen;
|
||||
}
|
||||
} else if (type == WIDGET_TYPE_MQTT_BUTTON) {
|
||||
void *h = NULL;
|
||||
char *mqtt = NULL;
|
||||
struct json_token val;
|
||||
int idx;
|
||||
|
||||
if (json_scanf(json, strlen(json), "{mqtt:%Q}", &mqtt) != 1) {
|
||||
LOG(LL_WARN, ("Widget '%s' is of type MQTT_BUTTON but does not have attribute 'mqtt'", widget->name));
|
||||
} else {
|
||||
while ((h = json_next_elem(json, strlen(json), h, ".mqtt", &idx, &val)) != NULL) {
|
||||
LOG(LL_INFO, ("[%d]: [%.*s]", idx, val.len, val.ptr));
|
||||
if (val.len>0 && val.ptr) {
|
||||
}
|
||||
}
|
||||
if(mqtt) free(mqtt);
|
||||
}
|
||||
}
|
||||
|
||||
return widget;
|
||||
|
Reference in New Issue
Block a user