readFromConfig() update

This commit is contained in:
cschwinne
2021-06-25 01:26:15 +02:00
parent 660de0b4e5
commit 1e5420e6a7
18 changed files with 80 additions and 38 deletions

View File

@@ -249,11 +249,13 @@ class UsermodTemperature : public Usermod {
/**
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
*/
void readFromConfig(JsonObject &root) {
bool readFromConfig(JsonObject &root) {
// we look for JSON object: {"Temperature": {"pin": 0, "degC": true}}
JsonObject top = root[FPSTR(_name)];
int8_t newTemperaturePin = temperaturePin;
bool configComplete = true;
if (!top.isNull() && top["pin"] != nullptr) {
if (top[FPSTR(_enabled)].is<bool>()) {
disabled = !top[FPSTR(_enabled)].as<bool>();
@@ -274,13 +276,14 @@ class UsermodTemperature : public Usermod {
DEBUG_PRINTLN(F("Temperature config (re)loaded."));
} else {
DEBUG_PRINTLN(F("No config found. (Using defaults.)"));
configComplete = false;
}
if (!initDone) {
// first run: reading from cfg.json
temperaturePin = newTemperaturePin;
} else {
// changing paramters from settings page
// changing parameters from settings page
if (newTemperaturePin != temperaturePin) {
// deallocate pin and release memory
delete oneWire;
@@ -290,6 +293,7 @@ class UsermodTemperature : public Usermod {
setup();
}
}
return configComplete;
}
uint16_t getId()