rearrange weather widget, add uv index

Close #1630
This commit is contained in:
MM20
2026-03-11 22:07:21 +01:00
parent 58f56b3706
commit a2621bee0b
18 changed files with 287 additions and 172 deletions

View File

@@ -45,6 +45,8 @@ data class Forecast(
val windDirection: Double? = null,
/** rain, in mm per hour **/
val precipitation: Double? = null,
/** UV index **/
val uvIndex: Double? = null,
/** whether this forecast is during nighttime (whether a moon icon should be used instead of sun) **/
val night: Boolean = false,
/** Location string **/
@@ -79,7 +81,7 @@ data class Forecast(
windDirection = windDirection ?: -1.0,
windSpeed = windSpeed ?: -1.0,
snow = -1.0,
snowProbability = -1
uvIndex = uvIndex ?: -1.0,
)
}
@@ -102,6 +104,7 @@ data class Forecast(
updateTime = entity.updateTime,
windDirection = entity.windDirection.takeIf { it >= 0.0 },
windSpeed = entity.windSpeed.takeIf { it >= 0.0 },
uvIndex = entity.uvIndex.takeIf { it >= 0.0 },
)
companion object {

View File

@@ -86,6 +86,7 @@ class BreezyWeatherProvider(
windSpeed = hourly.windSpeed?.toDouble()?.div(3.6),
precipProbability = hourly.precipProbability,
windDirection = hourly.windDirection?.toDouble(),
uvIndex = hourly.uvIndex?.toDouble(),
updateTime = lastUpdate,
night = isNight
)

View File

@@ -49,12 +49,12 @@ internal data class LocationForecast(
) {
@Serializable
internal data class Details(
@SerialName("air_temperature") val airTemperature: Double,
@SerialName("cloud_area_fraction") val cloudAreaFraction: Double,
@SerialName("relative_humidity") val relativeHumidity: Double,
@SerialName("wind_from_direction") val windFromDirection: Double,
@SerialName("wind_speed") val windSpeed: Double,
@SerialName("air_pressure_at_sea_level") val airPressureAtSeaLevel: Double,
@SerialName("air_temperature") val airTemperature: Double?,
@SerialName("cloud_area_fraction") val cloudAreaFraction: Double?,
@SerialName("relative_humidity") val relativeHumidity: Double?,
@SerialName("wind_from_direction") val windFromDirection: Double?,
@SerialName("wind_speed") val windSpeed: Double?,
@SerialName("air_pressure_at_sea_level") val airPressureAtSeaLevel: Double?,
)
}
@@ -70,7 +70,8 @@ internal data class LocationForecast(
@Serializable
internal data class Details(
@SerialName("precipitation_amount") val precipitationAmount: Double?
@SerialName("precipitation_amount") val precipitationAmount: Double?,
@SerialName("ultraviolet_index_clear_sky_max") val ultravioletIndexClearSkyMax: Double?,
)
}
}

View File

@@ -97,9 +97,9 @@ internal class MetNoProvider(
forecasts.add(
Forecast(
timestamp = timestamp,
temperature = details.airTemperature + 273.15,
temperature = (details.airTemperature ?: continue) + 273.15,
updateTime = updatedAt,
clouds = details.cloudAreaFraction.roundToInt(),
clouds = details.cloudAreaFraction?.roundToInt(),
humidity = details.relativeHumidity,
windDirection = details.windFromDirection,
windSpeed = details.windSpeed,
@@ -110,6 +110,7 @@ internal class MetNoProvider(
icon = iconForCode(symbolCode),
condition = conditionForCode(symbolCode),
precipitation = precipitationAmount,
uvIndex = nextHours.details?.ultravioletIndexClearSkyMax,
night = isNight(timestamp, lat, lon)
)
@@ -239,7 +240,7 @@ internal class MetNoProvider(
"lightrain", "lightrainshowers" -> Forecast.LIGHT_RAIN
"heavyrain", "heavyrainshowers" -> Forecast.HEAVY_RAIN
"rain" -> Forecast.RAIN
"rain", "rainshowers" -> Forecast.RAIN
"lightsleet", "lightsleetshowers", "heavysleet", "heavysleetshowers", "sleet" -> Forecast.SLEET

View File

@@ -68,14 +68,14 @@ data class WeatherResultClouds(
@Serializable
data class CurrentWeatherResultRain(
@SerialName("1h") val oneHour: Double,
@SerialName("3h") val threeHours: Double,
@SerialName("1h") val oneHour: Double?,
@SerialName("3h") val threeHours: Double?,
)
@Serializable
data class CurrentWeatherResultSnow(
@SerialName("1h") val oneHour: Double,
@SerialName("3h") val threeHours: Double,
@SerialName("1h") val oneHour: Double?,
@SerialName("3h") val threeHours: Double?,
)
@Serializable
@@ -117,7 +117,7 @@ data class ForecastResultSnow(
@Serializable
data class ForecastResultSys(
val pod: String,
val pod: String?,
)
@Serializable

View File

@@ -118,6 +118,7 @@ internal class PluginWeatherProvider(
provider = cursor[ForecastColumns.Provider] ?: continue,
providerUrl = cursor[ForecastColumns.ProviderUrl] ?: "",
clouds = cursor[ForecastColumns.Clouds],
uvIndex = cursor[ForecastColumns.UvIndex],
humidity = cursor[ForecastColumns.Humidity]?.toDouble(),
precipitation = cursor[ForecastColumns.Precipitation],
precipProbability = cursor[ForecastColumns.RainProbability],