diff options
Diffstat (limited to 'services/Weather.qml')
| -rw-r--r-- | services/Weather.qml | 19 |
1 files changed, 10 insertions, 9 deletions
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() |