mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 03:16:51 +01:00
Weather: get wind speed and direction from the Weather Notification app
The wind direction is approximate because we only get the quadrant, not a precise value
This commit is contained in:
parent
cc83021ae3
commit
477c27dcf0
@ -56,6 +56,10 @@ public class ParcelableWeather2 implements Parcelable {
|
||||
conditionBundle.getStringArray("weather_condition_types");
|
||||
weatherSpec.currentTemp = conditionBundle.getInt("weather_current_temp");
|
||||
|
||||
weatherSpec.windDirection = mapDirToDeg(conditionBundle.getString("weather_wind_direction"));
|
||||
weatherSpec.windSpeed = getSpeedInKMH(conditionBundle.getInt("weather_wind_speed"),
|
||||
conditionBundle.getString("weather_wind_speed_unit"));
|
||||
|
||||
String[] currentConditionType = conditionBundle.getStringArray("weather_condition_types");
|
||||
if (currentConditionType != null) {
|
||||
weatherSpec.currentConditionCode = weatherConditionTypesToOpenWeatherMapIds(currentConditionType[0]);
|
||||
@ -254,4 +258,28 @@ public class ParcelableWeather2 implements Parcelable {
|
||||
return 3200;
|
||||
}
|
||||
|
||||
}
|
||||
private int getSpeedInKMH(int speed, String incomingUnit) {
|
||||
float kmhSpeed = 0;
|
||||
switch (incomingUnit) {
|
||||
case "MPS":
|
||||
kmhSpeed = speed * 3.6f;
|
||||
break;
|
||||
case "MPH":
|
||||
kmhSpeed = speed * 1.6093f;
|
||||
break;
|
||||
case "KPH":
|
||||
kmhSpeed = speed;
|
||||
break;
|
||||
}
|
||||
return Math.round(kmhSpeed);
|
||||
}
|
||||
|
||||
private int mapDirToDeg(String dir) {
|
||||
return Math.round(WindDirection.valueOf(dir).ordinal() * 22.5f);
|
||||
}
|
||||
|
||||
private enum WindDirection { // see upstream code, we can't be more precise than getting the quadrant
|
||||
N, NNE, NE, ENE, E, ESE, SE, SSE, S, SSW, SW, WSW, W, WNW, NW, NNW
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user