diff --git a/backend/classes/ConfigFile.ts b/backend/classes/ConfigFile.ts index 2b3558c..59236b0 100644 --- a/backend/classes/ConfigFile.ts +++ b/backend/classes/ConfigFile.ts @@ -97,7 +97,7 @@ export default class { try { const jsonData = JSON.stringify(config, null, 4); fs.writeFileSync(this.filePath, jsonData, 'utf-8'); - this.cachedConfig = config; + this.cachedConfig = JSON.parse(JSON.stringify(config)); return true; } catch (error) { errorLog(`ConfigFile.write: Error writing config: ${error}`); diff --git a/backend/classes/LiveData.ts b/backend/classes/LiveData.ts index d5e4201..c4cfe51 100644 --- a/backend/classes/LiveData.ts +++ b/backend/classes/LiveData.ts @@ -1,7 +1,7 @@ import InterfaceLiveData from '../models/InterfaceLiveData.js'; export default class { - static defaultData: InterfaceLiveData = { + private static defaultData: InterfaceLiveData = { Timestamp: null, Inverter: { Export: -1, @@ -32,5 +32,9 @@ export default class { Power: -1 } }; + + static setDefault(): void { + this.data = JSON.parse(JSON.stringify(this.defaultData)); + } static data: InterfaceLiveData = this.defaultData; } diff --git a/backend/loop.ts b/backend/loop.ts index 827d8c5..0598fd8 100644 --- a/backend/loop.ts +++ b/backend/loop.ts @@ -16,8 +16,7 @@ export default async function (): Promise { infoLog('\n---------------------------------------------------------------'); infoLog('LOOP (' + ConfigFile.read().CheckSeconds + 's) --------------------|'); - LiveData.data = LiveData.defaultData; - + LiveData.setDefault(); const config: InterfaceConfig = ConfigFile.read(); infoLog(`Mode: '${config.Mode}'`);