Reassign to data, rather than separate settings

pull/3586/head
Rob Pilling 2024-09-30 08:46:46 +01:00
parent 0849edf198
commit 09bea87f18
1 changed files with 8 additions and 24 deletions

View File

@ -329,36 +329,20 @@ function readWeather() {
var weatherJson = require("Storage").readJSON('weather.json', 1);
// save updated weather data if available and it has been an hour since last updated
if (weatherJson && weatherJson.weather && weatherJson.weather.time && (data.time === undefined || (data.time + 3600000) < weatherJson.weather.time)) {
const newSettings = {
time: weatherJson.weather.time,
temp: weatherJson.weather.temp,
code: weatherJson.weather.code
};
require("Storage").writeJSON(
'mtnclock.json',
Object.assign(
require("Storage").readJSON('mtnclock.json', 1),
newSettings
)
);
data.time = weatherJson.weather.time;
data.temp = weatherJson.weather.temp;
data.code = weatherJson.weather.code;
require("Storage").writeJSON('mtnclock.json', data);
}
}
const _GB = global.GB;
global.GB = (event) => {
if (event.t==="weather") {
const newSettings = {
temp: event.temp,
code: event.code,
time: Date.now()
};
require("Storage").writeJSON(
'mtnclock.json',
Object.assign(
require("Storage").readJSON('mtnclock.json', 1),
newSettings
)
);
data.temp = event.temp;
data.code = event.code;
data.time = Date.now();
require("Storage").writeJSON('mtnclock.json', data);
setWeather();
}
if (_GB) setTimeout(_GB, 0, event);