Remove deprecated ArduinoJson methods

This commit is contained in:
Djuri 2025-01-05 23:13:05 +01:00
parent 178748b94d
commit 0999dd08ad
Signed by: djuri
GPG key ID: 61B9B2DDE5AA3AC1
3 changed files with 10 additions and 31 deletions

View file

@ -158,7 +158,7 @@ void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data)
// return; // return;
// } // }
if (doc.containsKey("block")) if (doc["block"].is<JsonObject>())
{ {
JsonObject block = doc["block"]; JsonObject block = doc["block"];
@ -168,7 +168,7 @@ void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data)
processNewBlock(block["height"].as<uint>()); processNewBlock(block["height"].as<uint>());
} }
else if (doc.containsKey("mempool-blocks")) else if (doc["mempool-blocks"].is<JsonArray>())
{ {
JsonArray blockInfo = doc["mempool-blocks"].as<JsonArray>(); JsonArray blockInfo = doc["mempool-blocks"].as<JsonArray>();
@ -181,7 +181,7 @@ void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data)
} }
void processNewBlock(uint32_t newBlockHeight) { void processNewBlock(uint32_t newBlockHeight) {
if (currentBlockHeight <= newBlockHeight) if (newBlockHeight <= currentBlockHeight)
{ {
return; return;
} }

View file

@ -127,7 +127,7 @@ namespace V2Notify
void handleV2Message(JsonDocument doc) void handleV2Message(JsonDocument doc)
{ {
if (doc.containsKey("blockheight")) if (doc["blockheight"].is<JsonObject>())
{ {
uint newBlockHeight = doc["blockheight"].as<uint>(); uint newBlockHeight = doc["blockheight"].as<uint>();
@ -138,13 +138,13 @@ namespace V2Notify
processNewBlock(newBlockHeight); processNewBlock(newBlockHeight);
} }
else if (doc.containsKey("blockfee")) else if (doc["blockfee"].is<JsonObject>())
{ {
uint medianFee = doc["blockfee"].as<uint>(); uint medianFee = doc["blockfee"].as<uint>();
processNewBlockFee(medianFee); processNewBlockFee(medianFee);
} }
else if (doc.containsKey("price")) else if (doc["price"].is<JsonObject>())
{ {
// Iterate through the key-value pairs of the "price" object // Iterate through the key-value pairs of the "price" object

View file

@ -612,15 +612,15 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json)
} }
// Handle DND settings // Handle DND settings
if (settings.containsKey("dnd")) { if (settings["dnd"].is<JsonObject>()) {
JsonObject dndObj = settings["dnd"]; JsonObject dndObj = settings["dnd"];
auto& ledHandler = getLedHandler(); auto& ledHandler = getLedHandler();
if (dndObj.containsKey("timeBasedEnabled")) { if (dndObj["timeBasedEnabled"].is<bool>()) {
ledHandler.setDNDTimeBasedEnabled(dndObj["timeBasedEnabled"].as<bool>()); ledHandler.setDNDTimeBasedEnabled(dndObj["timeBasedEnabled"].as<bool>());
} }
if (dndObj.containsKey("startHour") && dndObj.containsKey("startMinute") && if (dndObj["startHour"].is<uint8_t>() && dndObj["startMinute"].is<uint8_t>() &&
dndObj.containsKey("endHour") && dndObj.containsKey("endMinute")) { dndObj["endHour"].is<uint8_t>() && dndObj["endMinute"].is<uint8_t>()) {
ledHandler.setDNDTimeRange( ledHandler.setDNDTimeRange(
dndObj["startHour"].as<uint8_t>(), dndObj["startHour"].as<uint8_t>(),
dndObj["startMinute"].as<uint8_t>(), dndObj["startMinute"].as<uint8_t>(),
@ -1251,25 +1251,4 @@ void onApiLightsPost(AsyncWebServerRequest *request, uint8_t *data, size_t len,
pixels.show(); pixels.show();
request->send(200); request->send(200);
}
void onApiSettings(AsyncWebServerRequest *request, JsonVariant &json)
{
JsonObject settings = json.as<JsonObject>();
auto& ledHandler = getLedHandler();
if (settings.containsKey("dnd")) {
JsonObject dndObj = settings["dnd"];
if (dndObj.containsKey("timeBasedEnabled")) {
ledHandler.setDNDTimeBasedEnabled(dndObj["timeBasedEnabled"].as<bool>());
}
if (dndObj.containsKey("startHour") && dndObj.containsKey("startMinute") &&
dndObj.containsKey("endHour") && dndObj.containsKey("endMinute")) {
ledHandler.setDNDTimeRange(
dndObj["startHour"].as<uint8_t>(),
dndObj["startMinute"].as<uint8_t>(),
dndObj["endHour"].as<uint8_t>(),
dndObj["endMinute"].as<uint8_t>());
}
}
} }