Skip to content

Commit

Permalink
Use setting storage for weather cache
Browse files Browse the repository at this point in the history
  • Loading branch information
BlythMeister committed Oct 15, 2024
1 parent e8876ef commit b2222c8
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/366x366/companion/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { settingsStorage } from "settings";
import { localStorage } from "local-storage";
import { me as companion } from "companion";
import { weather } from "weather";

Expand Down Expand Up @@ -159,9 +158,9 @@ function sendWeather(unit) {
}

try {
localStorage.setItem("lastWeatherUnit", unitKey);
settingsStorage.setItem("lastWeatherUnit", unitKey);

let lastWeatherJson = localStorage.getItem("lastWeather");
let lastWeatherJson = settingsStorage.getItem("lastWeather");
if (lastWeatherJson != null) {
let lastWeather = JSON.parse(lastWeatherJson);
//console.log(`lastWeather: ${lastWeatherJson}`);
Expand Down Expand Up @@ -197,7 +196,7 @@ function sendWeather(unit) {
date: new Date(),
};
//console.log(`Weather:${JSON.stringify(sendData)}`);
localStorage.setItem("lastWeather", JSON.stringify(weatherData));
settingsStorage.setItem("lastWeather", JSON.stringify(weatherData));
msgq.send("weather", weatherData, true);
})
.catch((e) => {
Expand All @@ -209,7 +208,7 @@ function sendWeather(unit) {
location: e.message,
date: new Date(),
};
localStorage.setItem("lastWeather", null);
settingsStorage.setItem("lastWeather", null);
msgq.send("weather", errorWeather, true);
});
} catch (e) {
Expand All @@ -221,16 +220,16 @@ function sendWeather(unit) {
location: e.message,
date: new Date(),
};
localStorage.setItem("lastWeather", null);
settingsStorage.setItem("lastWeather", null);
msgq.send("weather", errorWeather, true);
}
}

function locationChange() {
try {
let lastWeatherUnit = localStorage.getItem("lastWeatherUnit");
let lastWeatherUnit = settingsStorage.getItem("lastWeatherUnit");
if (lastWeatherUnit != null) {
localStorage.setItem("lastWeather", null);
settingsStorage.setItem("lastWeather", null);
sendWeather(lastWeatherUnit);
}
} catch (e) {
Expand Down

0 comments on commit b2222c8

Please sign in to comment.