mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-05 15:15:46 +00:00
added Tasmota command json to get compatibility with SmartThings Tasmota Edge Driver (#1581)
* added Tasmota command json in order to get compatibility with SmartThings Tasmota Edge driver * revert missing parts
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
#include "cmd_local.h"
|
||||
#include "../new_pins.h"
|
||||
#include "../new_cfg.h"
|
||||
#include "../cJSON/cJSON.h"
|
||||
#if ENABLE_LITTLEFS
|
||||
#include "../littlefs/our_lfs.h"
|
||||
#endif
|
||||
@ -20,6 +21,37 @@ int parsePowerArgument(const char *s) {
|
||||
return atoi(s);
|
||||
}
|
||||
|
||||
|
||||
static commandResult_t cmnd_JsonCommand(const void *context, const char *cmd, const char *args, int cmdFlags) {
|
||||
cJSON *root = cJSON_Parse(args);
|
||||
if(!root) {
|
||||
ADDLOG_ERROR(LOG_FEATURE_CMD, "Invalid JSON input: %s", args);
|
||||
return CMD_RES_BAD_ARGUMENT;
|
||||
}
|
||||
|
||||
cJSON *element = root->child;
|
||||
while(element) {
|
||||
if (cJSON_IsString(element)) {
|
||||
char buffer[256];
|
||||
snprintf(buffer, sizeof(buffer), "%s %s", element->string, element->valuestring);
|
||||
CMD_ExecuteCommand(buffer, cmdFlags);
|
||||
}
|
||||
else if (cJSON_IsNumber(element)) {
|
||||
char buffer[256];
|
||||
if (element->valuedouble == (int)element->valuedouble) {
|
||||
snprintf(buffer, sizeof(buffer), "%s %d", element->string, (int)element->valuedouble);
|
||||
} else {
|
||||
snprintf(buffer, sizeof(buffer), "%s %.2f", element->string, element->valuedouble);
|
||||
}
|
||||
CMD_ExecuteCommand(buffer, cmdFlags);
|
||||
}
|
||||
element = element->next;
|
||||
}
|
||||
|
||||
cJSON_Delete(root);
|
||||
return CMD_RES_OK;
|
||||
}
|
||||
|
||||
static commandResult_t power(const void *context, const char *cmd, const char *args, int cmdFlags){
|
||||
//if (!wal_strnicmp(cmd, "POWER", 5)){
|
||||
int channel = 0;
|
||||
@ -474,5 +506,10 @@ int taslike_commands_init(){
|
||||
//cmddetail:"fn":"cmnd_stub","file":"cmnds/cmd_tasmota.c","requires":"",
|
||||
//cmddetail:"examples":""}
|
||||
CMD_RegisterCommand("Result", cmnd_stub, NULL);
|
||||
//cmddetail:{"name":"Json","args":"json array of commands",
|
||||
//cmddetail:"descr":"A stub for Tasmota",
|
||||
//cmddetail:"fn":"cmnd_JsonCommand","file":"cmnds/cmd_tasmota.c","requires":"",
|
||||
//cmddetail:"examples":""}
|
||||
CMD_RegisterCommand("Json", cmnd_JsonCommand, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user