qs: streamline weather condition detection in WeatherCard and LocationService
This commit is contained in:
@@ -17,15 +17,13 @@ UBox {
|
||||
readonly property bool weatherReady: LocationService.data.weather !== null
|
||||
// Test mode: set to "clear_day", "clear_night", "rain", "snow", "cloud" or "fog"
|
||||
property string testEffects: ""
|
||||
// Weather condition detection
|
||||
readonly property int currentWeatherCode: weatherReady ? LocationService.data.weather.current_weather.weathercode : 0
|
||||
readonly property bool isDayTime: weatherReady ? LocationService.data.weather.current_weather.is_day : true
|
||||
readonly property bool isRaining: testEffects === "rain" || (testEffects === "" && ((currentWeatherCode >= 51 && currentWeatherCode <= 67) || (currentWeatherCode >= 80 && currentWeatherCode <= 82)))
|
||||
readonly property bool isSnowing: testEffects === "snow" || (testEffects === "" && ((currentWeatherCode >= 71 && currentWeatherCode <= 77) || (currentWeatherCode >= 85 && currentWeatherCode <= 86)))
|
||||
readonly property bool isCloudy: testEffects === "cloud" || (testEffects === "" && (currentWeatherCode === 3))
|
||||
readonly property bool isFoggy: testEffects === "fog" || (testEffects === "" && (currentWeatherCode >= 40 && currentWeatherCode <= 49))
|
||||
readonly property bool isClearDay: testEffects === "clear_day" || (testEffects === "" && (currentWeatherCode === 0 && isDayTime))
|
||||
readonly property bool isClearNight: testEffects === "clear_night" || (testEffects === "" && (currentWeatherCode === 0 && !isDayTime))
|
||||
// Weather condition detection (delegates to LocationService, with testEffects override)
|
||||
readonly property bool isRaining: testEffects === "rain" || (testEffects === "" && LocationService.isRaining)
|
||||
readonly property bool isSnowing: testEffects === "snow" || (testEffects === "" && LocationService.isSnowing)
|
||||
readonly property bool isCloudy: testEffects === "cloud" || (testEffects === "" && LocationService.isCloudy)
|
||||
readonly property bool isFoggy: testEffects === "fog" || (testEffects === "" && LocationService.isFoggy)
|
||||
readonly property bool isClearDay: testEffects === "clear_day" || (testEffects === "" && LocationService.isClearDay)
|
||||
readonly property bool isClearNight: testEffects === "clear_night" || (testEffects === "" && LocationService.isClearNight)
|
||||
|
||||
implicitHeight: Math.max(100, content.implicitHeight + Style.marginXL * 2)
|
||||
|
||||
|
||||
@@ -27,6 +27,15 @@ Singleton {
|
||||
const lon = parseFloat(root.stableLongitude).toFixed(4);
|
||||
return `${lat}, ${lon}`;
|
||||
}
|
||||
// Weather condition detection
|
||||
readonly property int currentWeatherCode: data.weather ? data.weather.current_weather.weathercode : -1
|
||||
readonly property bool isDayTime: data.weather ? data.weather.current_weather.is_day : true
|
||||
readonly property bool isRaining: currentWeatherCode >= 0 && ((currentWeatherCode >= 51 && currentWeatherCode <= 67) || (currentWeatherCode >= 80 && currentWeatherCode <= 82) || (currentWeatherCode >= 95 && currentWeatherCode <= 99))
|
||||
readonly property bool isSnowing: currentWeatherCode >= 0 && ((currentWeatherCode >= 71 && currentWeatherCode <= 77) || (currentWeatherCode >= 85 && currentWeatherCode <= 86))
|
||||
readonly property bool isCloudy: currentWeatherCode >= 0 && (currentWeatherCode === 2 || currentWeatherCode === 3)
|
||||
readonly property bool isFoggy: currentWeatherCode >= 0 && (currentWeatherCode >= 40 && currentWeatherCode <= 49)
|
||||
readonly property bool isClearDay: currentWeatherCode >= 0 && (currentWeatherCode === 0 || currentWeatherCode === 1) && isDayTime
|
||||
readonly property bool isClearNight: currentWeatherCode >= 0 && (currentWeatherCode === 0 || currentWeatherCode === 1) && !isDayTime
|
||||
|
||||
function init() {
|
||||
Logger.i("Location", "Service started");
|
||||
|
||||
Reference in New Issue
Block a user