MCPcopy
hub / github.com/Koenkk/zigbee2mqtt / load

Method load

lib/state.ts:73–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

71 }
72
73 private load(): void {
74 this.state.clear();
75
76 if (existsSync(this.file)) {
77 try {
78 const stateObj = JSON.parse(readFileSync(this.file, "utf8")) as KeyValue;
79
80 for (const key in stateObj) {
81 this.state.set(key.startsWith("0x") ? key : Number.parseInt(key, 10), stateObj[key]);
82 }
83
84 logger.debug(`Loaded state from file ${this.file}`);
85 } catch (error) {
86 logger.debug(`Failed to load state from file ${this.file} (corrupt file?) (${(error as Error).message})`);
87 }
88 } else {
89 logger.debug(`Can't load state from file ${this.file} (doesn't exist)`);
90 }
91 }
92
93 private save(): void {
94 if (settings.get().advanced.cache_state_persistent) {

Callers 2

startMethod · 0.95

Calls 3

clearMethod · 0.80
setMethod · 0.80
debugMethod · 0.80

Tested by

no test coverage detected