mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
@@ -41,8 +41,7 @@ const Modules: FC = () => {
|
|||||||
send: fetchModules,
|
send: fetchModules,
|
||||||
error
|
error
|
||||||
} = useRequest(EMSESP.readModules, {
|
} = useRequest(EMSESP.readModules, {
|
||||||
initialData: [],
|
initialData: []
|
||||||
force: true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const { send: writeModules } = useRequest(
|
const { send: writeModules } = useRequest(
|
||||||
@@ -128,8 +127,7 @@ const Modules: FC = () => {
|
|||||||
.catch((error: Error) => {
|
.catch((error: Error) => {
|
||||||
toast.error(error.message);
|
toast.error(error.message);
|
||||||
})
|
})
|
||||||
.finally(async () => {
|
.finally(() => {
|
||||||
await fetchModules();
|
|
||||||
setNumChanges(0);
|
setNumChanges(0);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class FSPersistence {
|
|||||||
JsonObject jsonObject = jsonDocument.as<JsonObject>();
|
JsonObject jsonObject = jsonDocument.as<JsonObject>();
|
||||||
_statefulService->updateWithoutPropagation(jsonObject, _stateUpdater);
|
_statefulService->updateWithoutPropagation(jsonObject, _stateUpdater);
|
||||||
#ifdef EMSESP_DEBUG
|
#ifdef EMSESP_DEBUG
|
||||||
|
Serial.println();
|
||||||
Serial.printf("Reading settings from %s ", _filePath);
|
Serial.printf("Reading settings from %s ", _filePath);
|
||||||
serializeJson(jsonDocument, Serial);
|
serializeJson(jsonDocument, Serial);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
@@ -40,7 +41,9 @@ class FSPersistence {
|
|||||||
// If we reach here we have not been successful in loading the config,
|
// If we reach here we have not been successful in loading the config,
|
||||||
// hard-coded emergency defaults are now applied.
|
// hard-coded emergency defaults are now applied.
|
||||||
#ifdef EMSESP_DEBUG
|
#ifdef EMSESP_DEBUG
|
||||||
Serial.println("Applying defaults to " + String(_filePath));
|
Serial.println();
|
||||||
|
Serial.printf("Applying defaults to %s ", _filePath);
|
||||||
|
Serial.println();
|
||||||
#endif
|
#endif
|
||||||
applyDefaults();
|
applyDefaults();
|
||||||
writeToFS(); // added to make sure the initial file is created
|
writeToFS(); // added to make sure the initial file is created
|
||||||
@@ -72,6 +75,7 @@ class FSPersistence {
|
|||||||
|
|
||||||
// serialize the data to the file
|
// serialize the data to the file
|
||||||
#ifdef EMSESP_DEBUG
|
#ifdef EMSESP_DEBUG
|
||||||
|
Serial.println();
|
||||||
Serial.printf("Writing settings to %s ", _filePath);
|
Serial.printf("Writing settings to %s ", _filePath);
|
||||||
serializeJson(jsonDocument, Serial);
|
serializeJson(jsonDocument, Serial);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ void WebModulesService::loop() {
|
|||||||
// this creates the modules file, saving it to the FS
|
// this creates the modules file, saving it to the FS
|
||||||
// and also calls when the Modules web page is refreshed
|
// and also calls when the Modules web page is refreshed
|
||||||
void WebModules::read(WebModules & webModules, JsonObject root) {
|
void WebModules::read(WebModules & webModules, JsonObject root) {
|
||||||
// EMSESP::logger().debug("module read called"); // TODO remove
|
#ifdef EMSESP_DEBUG
|
||||||
|
EMSESP::logger().debug("module read called");
|
||||||
|
#endif
|
||||||
|
|
||||||
JsonDocument doc_modules;
|
JsonDocument doc_modules;
|
||||||
JsonObject root_modules = doc_modules.to<JsonObject>();
|
JsonObject root_modules = doc_modules.to<JsonObject>();
|
||||||
@@ -67,7 +69,9 @@ void WebModules::read(WebModules & webModules, JsonObject root) {
|
|||||||
// and then apply the enable/disable
|
// and then apply the enable/disable
|
||||||
// it's also called on a save
|
// it's also called on a save
|
||||||
StateUpdateResult WebModules::update(JsonObject root, WebModules & webModules) {
|
StateUpdateResult WebModules::update(JsonObject root, WebModules & webModules) {
|
||||||
// EMSESP::logger().debug("module update called"); // TODO remove
|
#ifdef EMSESP_DEBUG
|
||||||
|
EMSESP::logger().debug("module update called");
|
||||||
|
#endif
|
||||||
|
|
||||||
if (root["modules"].is<JsonArray>()) {
|
if (root["modules"].is<JsonArray>()) {
|
||||||
for (const JsonObject module : root["modules"].as<JsonArray>()) {
|
for (const JsonObject module : root["modules"].as<JsonArray>()) {
|
||||||
@@ -76,7 +80,7 @@ StateUpdateResult WebModules::update(JsonObject root, WebModules & webModules) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return StateUpdateResult::CHANGED;
|
return StateUpdateResult::CHANGED_RESTART;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|||||||
Reference in New Issue
Block a user