1
0
Fork 0

bthrm - Convert old cache to new settings if found

master
Martin Boonk 2024-04-10 22:21:05 +02:00
parent 7e0792409c
commit 8363f9aa39
2 changed files with 11 additions and 5 deletions

View File

@ -16,6 +16,14 @@ exports.enable = () => {
log("Settings: ", settings); log("Settings: ", settings);
//this is for compatibility with 0.18 and older
let oldCache = require('Storage').readJSON("bthrm.cache.json", true);
if(oldCache){
settings.cache = oldCache;
require('Storage').writeJSON("bthrm.json", settings);
require('Storage').erase("bthrm.cache.json");
}
if (settings.enabled && settings.cache){ if (settings.enabled && settings.cache){
log("Start"); log("Start");

View File

@ -129,11 +129,9 @@
"0x2a19", // Battery "0x2a19", // Battery
]; ];
var characteristicsToCache = function(characteristics, deviceId) { var characteristicsToCache = function(characteristics) {
log("Cache characteristics"); log("Cache characteristics");
let cache = { let cache = {};
id: deviceId
};
if (!cache.characteristics) cache.characteristics = {}; if (!cache.characteristics) cache.characteristics = {};
for (var c of characteristics){ for (var c of characteristics){
//"handle_value":16,"handle_decl":15 //"handle_value":16,"handle_decl":15
@ -240,7 +238,7 @@
return promise.then(()=>{ return promise.then(()=>{
log("Connection established, saving cache"); log("Connection established, saving cache");
characteristicsToCache(characteristics, deviceId); characteristicsToCache(characteristics);
}); });
} }