Skip to content

Commit

Permalink
Added deepcloning for live data reset
Browse files Browse the repository at this point in the history
  • Loading branch information
davbauer committed Apr 1, 2024
1 parent ac4fd1d commit d8dc6ce
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/classes/ConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
6 changes: 5 additions & 1 deletion backend/classes/LiveData.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
}
3 changes: 1 addition & 2 deletions backend/loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export default async function (): Promise<void> {
infoLog('\n---------------------------------------------------------------');
infoLog('LOOP (' + ConfigFile.read().CheckSeconds + 's) --------------------|');

LiveData.data = LiveData.defaultData;

LiveData.setDefault();
const config: InterfaceConfig = ConfigFile.read();

infoLog(`Mode: '${config.Mode}'`);
Expand Down

0 comments on commit d8dc6ce

Please sign in to comment.