From 87b491d8e794995950c6667e1d831061e36aa186 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sun, 10 Aug 2025 23:15:32 +1000 Subject: lock: add weather Also refactor weather service --- services/Weather.qml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'services') diff --git a/services/Weather.qml b/services/Weather.qml index 38750ae..02458c2 100644 --- a/services/Weather.qml +++ b/services/Weather.qml @@ -9,10 +9,13 @@ Singleton { id: root property string loc - property string icon - property string description - property string tempC: "0°C" - property string tempF: "0°F" + property var cc + property var forecast + readonly property string icon: cc ? Icons.getWeatherIcon(cc.weatherCode) : "cloud_alert" + readonly property string description: cc?.weatherDesc[0].value ?? qsTr("No weather") + readonly property string temp: Config.services.useFahrenheit ? `${cc?.temp_F ?? 0}°F` : `${cc?.temp_C ?? 0}°C` + readonly property string feelsLike: Config.services.useFahrenheit ? `${cc?.FeelsLikeF ?? 0}°F` : `${cc?.FeelsLikeC ?? 0}°C` + readonly property int humidity: cc?.humidity ?? 0 function reload(): void { if (Config.services.weatherLocation) @@ -25,11 +28,9 @@ Singleton { } onLocChanged: Requests.get(`https://wttr.in/${loc}?format=j1`, text => { - const json = JSON.parse(text).current_condition[0]; - icon = Icons.getWeatherIcon(json.weatherCode); - description = json.weatherDesc[0].value; - tempC = `${parseFloat(json.temp_C)}°C`; - tempF = `${parseFloat(json.temp_F)}°F`; + const json = JSON.parse(text); + cc = json.current_condition[0]; + forecast = json.weather; }) Component.onCompleted: reload() -- cgit v1.2.3-freya