Merge pull request #1784 from proddy/feat_modules

Feat modules
This commit is contained in:
Proddy
2024-05-30 22:03:53 +02:00
committed by GitHub
3 changed files with 14 additions and 8 deletions

View File

@@ -41,8 +41,7 @@ const Modules: FC = () => {
send: fetchModules,
error
} = useRequest(EMSESP.readModules, {
initialData: [],
force: true
initialData: []
});
const { send: writeModules } = useRequest(
@@ -128,8 +127,7 @@ const Modules: FC = () => {
.catch((error: Error) => {
toast.error(error.message);
})
.finally(async () => {
await fetchModules();
.finally(() => {
setNumChanges(0);
});
};

View File

@@ -27,6 +27,7 @@ class FSPersistence {
JsonObject jsonObject = jsonDocument.as<JsonObject>();
_statefulService->updateWithoutPropagation(jsonObject, _stateUpdater);
#ifdef EMSESP_DEBUG
Serial.println();
Serial.printf("Reading settings from %s ", _filePath);
serializeJson(jsonDocument, Serial);
Serial.println();
@@ -40,7 +41,9 @@ class FSPersistence {
// If we reach here we have not been successful in loading the config,
// hard-coded emergency defaults are now applied.
#ifdef EMSESP_DEBUG
Serial.println("Applying defaults to " + String(_filePath));
Serial.println();
Serial.printf("Applying defaults to %s ", _filePath);
Serial.println();
#endif
applyDefaults();
writeToFS(); // added to make sure the initial file is created
@@ -72,6 +75,7 @@ class FSPersistence {
// serialize the data to the file
#ifdef EMSESP_DEBUG
Serial.println();
Serial.printf("Writing settings to %s ", _filePath);
serializeJson(jsonDocument, Serial);
Serial.println();

View File

@@ -44,7 +44,9 @@ void WebModulesService::loop() {
// this creates the modules file, saving it to the FS
// and also calls when the Modules web page is refreshed
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;
JsonObject root_modules = doc_modules.to<JsonObject>();
@@ -67,7 +69,9 @@ void WebModules::read(WebModules & webModules, JsonObject root) {
// and then apply the enable/disable
// it's also called on a save
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>()) {
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