mirror of
https://github.com/skydiver/ewelink-api.git
synced 2025-12-27 23:46:34 +01:00
saveDevicesCache: use v2 API
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const { _get } = require('../helpers/utilities');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Save devices cache file (useful for using zeroconf)
|
||||
@@ -10,20 +8,13 @@ module.exports = {
|
||||
async saveDevicesCache(fileName = './devices-cache.json') {
|
||||
const devices = await this.getDevices();
|
||||
|
||||
const error = _get(devices, 'error', false);
|
||||
|
||||
if (error || !devices) {
|
||||
return devices;
|
||||
}
|
||||
|
||||
const jsonContent = JSON.stringify(devices, null, 2);
|
||||
|
||||
try {
|
||||
fs.writeFileSync(fileName, jsonContent, 'utf8');
|
||||
return { status: 'ok', file: fileName };
|
||||
} catch (e) {
|
||||
console.log('An error occured while writing JSON Object to File.');
|
||||
return { error: e.toString() };
|
||||
throw new Error('An error occured while writing JSON Object to File.');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user