First start of MQTT buttons

This commit is contained in:
Pim van Pelt
2017-12-02 16:51:09 +01:00
parent c315de560f
commit b8e5637c8b
9 changed files with 97 additions and 13 deletions

View File

@ -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;