homebridge-econet-rheem
Version:
Homebridge plugin based on pyeconet for control of Rheem water heaters
25 lines • 812 B
JavaScript
import fs from 'fs';
export const STORAGE_FILE_NAME = 'econetRheem.json';
export const STORAGE_KEY_AUTH = 'auth';
export const STORAGE_KEY_MQTT = 'mqtt';
export const STORAGE_KEY_RECOVERY_RATES = 'rates';
function readStorage(filePath) {
if (!fs.existsSync(filePath)) {
return {};
}
const data = fs.readFileSync(filePath, 'utf-8');
return JSON.parse(data);
}
function writeStorage(filePath, storage) {
fs.writeFileSync(filePath, JSON.stringify(storage, null, 2));
}
export function safeGetItem(filePath, key) {
const storage = readStorage(filePath);
return storage[key] ?? null;
}
export function safeSetItem(filePath, key, value) {
const storage = readStorage(filePath);
storage[key] = value;
writeStorage(filePath, storage);
}
//# sourceMappingURL=storage.js.map