Harden temperature assignment clearing
This commit is contained in:
@@ -2179,8 +2179,24 @@ void handleTempAssign() {
|
||||
}
|
||||
|
||||
void handleTempClear() {
|
||||
String body = server.arg("plain");
|
||||
|
||||
if (body.length() == 0) {
|
||||
for (int i = 0; i < MAX_TEMP_SENSORS; i++) {
|
||||
appConfig.tempSensors[i].address = "";
|
||||
appConfig.tempSensors[i].enabled = false;
|
||||
appConfig.tempSensors[i].weather = false;
|
||||
sensors.tempsF[i] = -127.0;
|
||||
sensors.online[i] = false;
|
||||
}
|
||||
|
||||
saveConfig();
|
||||
sendConfigJson();
|
||||
return;
|
||||
}
|
||||
|
||||
DynamicJsonDocument doc(512);
|
||||
DeserializationError error = deserializeJson(doc, server.arg("plain"));
|
||||
DeserializationError error = deserializeJson(doc, body);
|
||||
|
||||
if (error) {
|
||||
server.send(400, "application/json", "{\"ok\":false,\"error\":\"invalid_json\"}");
|
||||
@@ -2203,10 +2219,11 @@ void handleTempClear() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!clearTempSensor(configIndex)) {
|
||||
server.send(400, "application/json", "{\"ok\":false,\"error\":\"unknown_temp_sensor\"}");
|
||||
return;
|
||||
}
|
||||
appConfig.tempSensors[configIndex].address = "";
|
||||
appConfig.tempSensors[configIndex].enabled = false;
|
||||
appConfig.tempSensors[configIndex].weather = false;
|
||||
sensors.tempsF[configIndex] = -127.0;
|
||||
sensors.online[configIndex] = false;
|
||||
|
||||
saveConfig();
|
||||
sendConfigJson();
|
||||
|
||||
Reference in New Issue
Block a user