[BT] Clean KnownBTAction function (#2062)
Co-authored-by: Florian <1technophile@users.noreply.github.com>
This commit is contained in:
1 parent
4b20976a08
commit
0b4c6ef107
1 file changed
+26
-31
+26
-31
@@ -1387,67 +1387,62 @@ void startBTActionTask() {
|
|||||||
|
|
||||||
# if BLEDecoder
|
# if BLEDecoder
|
||||||
void KnownBTActions(JsonObject& BTdata) {
|
void KnownBTActions(JsonObject& BTdata) {
|
||||||
|
if (!BTdata.containsKey("id")) {
|
||||||
|
Log.error(F("BLE mac address missing" CR));
|
||||||
|
gatewayState = GatewayState::ERROR;
|
||||||
|
return;
|
||||||
|
}
|
||||||
BLEAction action;
|
BLEAction action;
|
||||||
memset(&action, 0, sizeof(BLEAction));
|
memset(&action, 0, sizeof(BLEAction));
|
||||||
if (BTdata.containsKey("model_id") && BTdata["model_id"].is<const char*>() && BTdata["model_id"] == "X1") {
|
|
||||||
strcpy(action.addr, (const char*)BTdata["id"]);
|
strcpy(action.addr, (const char*)BTdata["id"]);
|
||||||
action.write = true;
|
action.write = true;
|
||||||
|
action.ttl = 3;
|
||||||
|
bool res = false;
|
||||||
|
if (BTdata.containsKey("model_id") && BTdata["model_id"].is<const char*>()) {
|
||||||
|
if (BTdata["model_id"] == "X1") {
|
||||||
|
if (BTdata.containsKey("cmd") && BTdata["cmd"].is<const char*>()) {
|
||||||
|
action.value_type = BLE_VAL_STRING;
|
||||||
std::string val = BTdata["cmd"].as<std::string>(); // Fix #1694
|
std::string val = BTdata["cmd"].as<std::string>(); // Fix #1694
|
||||||
action.value = val;
|
action.value = val;
|
||||||
action.ttl = 3;
|
|
||||||
createOrUpdateDevice(action.addr, device_flags_connect,
|
createOrUpdateDevice(action.addr, device_flags_connect,
|
||||||
TheengsDecoder::BLE_ID_NUM::SBS1, 1);
|
TheengsDecoder::BLE_ID_NUM::SBS1, 1);
|
||||||
BLEactions.push_back(action);
|
res = true;
|
||||||
startBTActionTask();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (BTdata.containsKey("model_id") && BTdata["model_id"].is<const char*>()) {
|
} else if (BTdata["model_id"] == "W270160X") {
|
||||||
if (BTdata["model_id"] == "W270160X") {
|
|
||||||
if (!BTdata.containsKey("id")) {
|
|
||||||
Log.error(F("BLE mac address missing" CR));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
strcpy(action.addr, (const char*)BTdata["id"]);
|
|
||||||
action.write = true;
|
|
||||||
if (BTdata.containsKey("tilt") && BTdata["tilt"].is<int>()) {
|
if (BTdata.containsKey("tilt") && BTdata["tilt"].is<int>()) {
|
||||||
action.value_type = BLE_VAL_INT;
|
action.value_type = BLE_VAL_INT;
|
||||||
|
res = true;
|
||||||
} else if (BTdata.containsKey("tilt") && BTdata["tilt"].is<const char*>()) {
|
} else if (BTdata.containsKey("tilt") && BTdata["tilt"].is<const char*>()) {
|
||||||
action.value_type = BLE_VAL_STRING;
|
action.value_type = BLE_VAL_STRING;
|
||||||
} else {
|
res = true;
|
||||||
Log.error(F("BLE value type invalid" CR));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (res) {
|
||||||
std::string val = BTdata["tilt"].as<std::string>(); // Fix #1694
|
std::string val = BTdata["tilt"].as<std::string>(); // Fix #1694
|
||||||
action.value = val;
|
action.value = val;
|
||||||
action.ttl = 3;
|
|
||||||
createOrUpdateDevice(action.addr, device_flags_connect,
|
createOrUpdateDevice(action.addr, device_flags_connect,
|
||||||
TheengsDecoder::BLE_ID_NUM::SBBT, 1);
|
TheengsDecoder::BLE_ID_NUM::SBBT, 1);
|
||||||
BLEactions.push_back(action);
|
|
||||||
startBTActionTask();
|
|
||||||
return;
|
|
||||||
} else if (BTdata["model_id"] == "W070160X") {
|
|
||||||
if (!BTdata.containsKey("id")) {
|
|
||||||
Log.error(F("BLE mac address missing" CR));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
strcpy(action.addr, (const char*)BTdata["id"]);
|
} else if (BTdata["model_id"] == "W070160X") {
|
||||||
action.write = true;
|
|
||||||
if (BTdata.containsKey("position") && BTdata["position"].is<int>()) {
|
if (BTdata.containsKey("position") && BTdata["position"].is<int>()) {
|
||||||
action.value_type = BLE_VAL_INT;
|
action.value_type = BLE_VAL_INT;
|
||||||
|
res = true;
|
||||||
} else if (BTdata.containsKey("position") && BTdata["position"].is<const char*>()) {
|
} else if (BTdata.containsKey("position") && BTdata["position"].is<const char*>()) {
|
||||||
action.value_type = BLE_VAL_STRING;
|
action.value_type = BLE_VAL_STRING;
|
||||||
} else {
|
res = true;
|
||||||
Log.error(F("BLE value type invalid" CR));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (res) {
|
||||||
std::string val = BTdata["position"].as<std::string>(); // Fix #1694
|
std::string val = BTdata["position"].as<std::string>(); // Fix #1694
|
||||||
action.value = val;
|
action.value = val;
|
||||||
action.ttl = 3;
|
|
||||||
createOrUpdateDevice(action.addr, device_flags_connect,
|
createOrUpdateDevice(action.addr, device_flags_connect,
|
||||||
TheengsDecoder::BLE_ID_NUM::SBCU, 1);
|
TheengsDecoder::BLE_ID_NUM::SBCU, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (res) {
|
||||||
BLEactions.push_back(action);
|
BLEactions.push_back(action);
|
||||||
startBTActionTask();
|
startBTActionTask();
|
||||||
return;
|
} else {
|
||||||
|
Log.error(F("BLE action not recognized" CR));
|
||||||
|
gatewayState = GatewayState::ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user