From 21d06aab3a9d37884ce0efdf642b5b0e3210b52a Mon Sep 17 00:00:00 2001 From: timklge <2026103+timklge@users.noreply.github.com> Date: Sat, 3 May 2025 17:00:55 +0200 Subject: [PATCH] Remove custom wind speed unit setting and always use imperial / metric as set in profile (#115) --- README.md | 4 ++-- app/build.gradle.kts | 1 + .../kotlin/de/timklge/karooheadwind/DataStore.kt | 6 +----- .../de/timklge/karooheadwind/HeadwindSettings.kt | 1 - .../karooheadwind/screens/SettingsScreen.kt | 16 ---------------- .../openmeteo/OpenMeteoWeatherProvider.kt | 4 +++- 6 files changed, 7 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 3780b0f..d20ee16 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ After installing this app on your Karoo and opening it once from the main menu, The app can use OpenMeteo or OpenWeatherMap as providers for live weather data. -- OpenMeteo is the default provider and does not require any configuration. -- OpenWeatherMap can provide more accurate data for some locations. Forecasts along the loaded route are not available using OpenWeatherMap. OpenWeatherMap is free for personal use, but you need to register at https://openweathermap.org/home/sign_in and obtain a one call API key (e. g. by subscribing to "One Call API 3.0" from the [pricing page](https://openweathermap.org/price)). You can enter your API key in the app settings. Please note that it can take a few hours before OpenWeatherMap enables the key. You can check if your key is enabled by entering it in the app settings and pressing "Test API Key". +- OpenMeteo is the default provider and does not require any configuration. Wind speed will be reported in km/h if your karoo is set to metric units or mph if set to imperial. +- OpenWeatherMap can provide more accurate data for some locations. Forecasts along the loaded route are not available using OpenWeatherMap. OpenWeatherMap is free for personal use, but you need to register at https://openweathermap.org/home/sign_in and obtain a one call API key (e. g. by subscribing to "One Call API 3.0" from the [pricing page](https://openweathermap.org/price)). You can enter your API key in the app settings. Please note that it can take a few hours before OpenWeatherMap enables the key. You can check if your key is enabled by entering it in the app settings and pressing "Test API Key". Wind speed will be reported in meters per second if your Karoo is set to metric units and miles per hour if set to imperial. The app will automatically attempt to download weather data from the selected data provider once your device has acquired a GPS fix. Your location is rounded to approximately three kilometers to maintain privacy. New weather data is downloaded when you ride more than three kilometers from the location where the weather data was downloaded for or after one hour at the latest. diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d27f80d..505b0fc 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -94,6 +94,7 @@ tasks.register("generateManifest") { "developer" to "github.com/timklge", "description" to "Open-source extension that provides headwind direction, wind speed, forecast and other weather data fields.", "releaseNotes" to "* Fix weather data download from Open-Meteo via iOS companion app (thx @keefar!)\n" + + "* Remove custom wind speed unit setting and always use imperial / metric as set in profile\n" + "* Add relative grade, relative elevation gain data fields\n" + "* Fix precipitation forecast field\n" + "* Interpolate between forecasted and current weather data\n" + diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/DataStore.kt b/app/src/main/kotlin/de/timklge/karooheadwind/DataStore.kt index 86fa1d4..5e8ddd4 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/DataStore.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/DataStore.kt @@ -112,11 +112,7 @@ fun Context.streamSettings(karooSystemService: KarooSystemService): Flow( HeadwindSettings.defaultSettings) - val preferredUnits = karooSystemService.streamUserProfile().first().preferredUnit - - defaultSettings.copy( - windUnit = if (preferredUnits.distance == UserProfile.PreferredUnit.UnitType.METRIC) WindUnit.KILOMETERS_PER_HOUR else WindUnit.MILES_PER_HOUR, - ) + defaultSettings.copy() } } catch(e: Throwable){ Log.e(KarooHeadwindExtension.TAG, "Failed to read preferences", e) diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/HeadwindSettings.kt b/app/src/main/kotlin/de/timklge/karooheadwind/HeadwindSettings.kt index ea2a21a..af5e632 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/HeadwindSettings.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/HeadwindSettings.kt @@ -65,7 +65,6 @@ data class HeadwindStats( @Serializable data class HeadwindSettings( - val windUnit: WindUnit = WindUnit.KILOMETERS_PER_HOUR, val welcomeDialogAccepted: Boolean = false, val windDirectionIndicatorTextSetting: WindDirectionIndicatorTextSetting = WindDirectionIndicatorTextSetting.HEADWIND_SPEED, val windDirectionIndicatorSetting: WindDirectionIndicatorSetting = WindDirectionIndicatorSetting.HEADWIND_DIRECTION, diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/screens/SettingsScreen.kt b/app/src/main/kotlin/de/timklge/karooheadwind/screens/SettingsScreen.kt index 80ba551..dba5b5e 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/screens/SettingsScreen.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/screens/SettingsScreen.kt @@ -63,7 +63,6 @@ fun SettingsScreen(onFinish: () -> Unit) { val coroutineScope = rememberCoroutineScope() val karooSystem = remember { KarooSystemService(ctx) } - var selectedWindUnit by remember { mutableStateOf(WindUnit.KILOMETERS_PER_HOUR) } var selectedWindDirectionIndicatorTextSetting by remember { mutableStateOf( WindDirectionIndicatorTextSetting.HEADWIND_SPEED @@ -86,7 +85,6 @@ fun SettingsScreen(onFinish: () -> Unit) { LaunchedEffect(Unit) { ctx.streamSettings(karooSystem).collect { settings -> - selectedWindUnit = settings.windUnit selectedWindDirectionIndicatorTextSetting = settings.windDirectionIndicatorTextSetting selectedWindDirectionIndicatorSetting = settings.windDirectionIndicatorSetting selectedRoundLocationSetting = settings.roundLocationTo @@ -114,7 +112,6 @@ fun SettingsScreen(onFinish: () -> Unit) { Log.d(KarooHeadwindExtension.TAG, "Saving settings") val newSettings = HeadwindSettings( - windUnit = selectedWindUnit, welcomeDialogAccepted = true, windDirectionIndicatorSetting = selectedWindDirectionIndicatorSetting, windDirectionIndicatorTextSetting = selectedWindDirectionIndicatorTextSetting, @@ -183,19 +180,6 @@ fun SettingsScreen(onFinish: () -> Unit) { WindDirectionIndicatorTextSetting.entries.find { unit -> unit.id == selectedOption.id }!! } - val windSpeedUnitDropdownOptions = - WindUnit.entries.toList().map { unit -> DropdownOption(unit.id, unit.label) } - val windSpeedUnitInitialSelection by remember(selectedWindUnit) { - mutableStateOf(windSpeedUnitDropdownOptions.find { option -> option.id == selectedWindUnit.id }!!) - } - Dropdown( - label = "Wind Speed Unit", - options = windSpeedUnitDropdownOptions, - selected = windSpeedUnitInitialSelection - ) { selectedOption -> - selectedWindUnit = WindUnit.entries.find { unit -> unit.id == selectedOption.id }!! - } - val roundLocationDropdownOptions = RoundLocationSetting.entries.toList() .map { unit -> DropdownOption(unit.id, unit.label) } val roundLocationInitialSelection by remember(selectedRoundLocationSetting) { diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherProvider.kt b/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherProvider.kt index b2ae50c..a865993 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherProvider.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/weatherprovider/openmeteo/OpenMeteoWeatherProvider.kt @@ -6,6 +6,7 @@ import de.timklge.karooheadwind.KarooHeadwindExtension import de.timklge.karooheadwind.PrecipitationUnit import de.timklge.karooheadwind.TemperatureUnit import de.timklge.karooheadwind.WeatherDataProvider +import de.timklge.karooheadwind.WindUnit import de.timklge.karooheadwind.datatypes.GpsCoordinates import de.timklge.karooheadwind.jsonWithUnknownKeys import de.timklge.karooheadwind.weatherprovider.WeatherDataResponse @@ -30,12 +31,13 @@ class OpenMeteoWeatherProvider : WeatherProvider { private suspend fun makeOpenMeteoWeatherRequest(karooSystemService: KarooSystemService, gpsCoordinates: List, settings: HeadwindSettings, profile: UserProfile?): HttpResponseState.Complete { val precipitationUnit = if (profile?.preferredUnit?.distance != UserProfile.PreferredUnit.UnitType.IMPERIAL) PrecipitationUnit.MILLIMETERS else PrecipitationUnit.INCH val temperatureUnit = if (profile?.preferredUnit?.temperature != UserProfile.PreferredUnit.UnitType.IMPERIAL) TemperatureUnit.CELSIUS else TemperatureUnit.FAHRENHEIT + val windUnit = if (profile?.preferredUnit?.distance != UserProfile.PreferredUnit.UnitType.IMPERIAL) WindUnit.KILOMETERS_PER_HOUR else WindUnit.MILES_PER_HOUR val response = callbackFlow { // https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41¤t=surface_pressure,pressure_msl,temperature_2m,relative_humidity_2m,precipitation,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m,wind_gusts_10m&hourly=temperature_2m,precipitation_probability,precipitation,weather_code,wind_speed_10m,wind_direction_10m,wind_gusts_10m&timeformat=unixtime&past_hours=1&forecast_days=1&forecast_hours=12 val lats = gpsCoordinates.joinToString(",") { String.format(Locale.US, "%.6f", it.lat) } val lons = gpsCoordinates.joinToString(",") { String.format(Locale.US, "%.6f", it.lon) } - val url = "https://api.open-meteo.com/v1/forecast?latitude=${lats}&longitude=${lons}¤t=surface_pressure,pressure_msl,temperature_2m,relative_humidity_2m,precipitation,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m,wind_gusts_10m&hourly=temperature_2m,precipitation_probability,precipitation,weather_code,wind_speed_10m,wind_direction_10m,wind_gusts_10m&timeformat=unixtime&past_hours=0&forecast_days=1&forecast_hours=12&wind_speed_unit=${settings.windUnit.id}&precipitation_unit=${precipitationUnit.id}&temperature_unit=${temperatureUnit.id}" + val url = "https://api.open-meteo.com/v1/forecast?latitude=${lats}&longitude=${lons}¤t=surface_pressure,pressure_msl,temperature_2m,relative_humidity_2m,precipitation,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m,wind_gusts_10m&hourly=temperature_2m,precipitation_probability,precipitation,weather_code,wind_speed_10m,wind_direction_10m,wind_gusts_10m&timeformat=unixtime&past_hours=0&forecast_days=1&forecast_hours=12&wind_speed_unit=${windUnit.id}&precipitation_unit=${precipitationUnit.id}&temperature_unit=${temperatureUnit.id}" Log.d(KarooHeadwindExtension.TAG, "Http request to ${url}...")