From b2222c8d60501d4e9bf1f9072fbf073665261cda Mon Sep 17 00:00:00 2001 From: Chris Blyth Date: Tue, 15 Oct 2024 18:17:23 +0100 Subject: [PATCH] Use setting storage for weather cache --- src/366x366/companion/index.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/366x366/companion/index.js b/src/366x366/companion/index.js index 65a4331..87fe922 100644 --- a/src/366x366/companion/index.js +++ b/src/366x366/companion/index.js @@ -1,5 +1,4 @@ import { settingsStorage } from "settings"; -import { localStorage } from "local-storage"; import { me as companion } from "companion"; import { weather } from "weather"; @@ -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}`); @@ -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) => { @@ -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) { @@ -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) {