bthrm - Convert old cache to new settings if found

pull/3349/head
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);
//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){
log("Start");

View File

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