1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 13:26:50 +01:00

Fossil/Skagen Hybrids: Add support for ultraviolet index and rain probability

Updates WeatherSpec to v3 to add fields for UV index and precipitation probability
Co-authored-by: Enrico Brambilla <enricobilla@noreply.codeberg.org>
Co-committed-by: Enrico Brambilla <enricobilla@noreply.codeberg.org>
This commit is contained in:
Enrico Brambilla 2023-06-05 19:52:26 +00:00 committed by Arjan Schrijver
parent 7e1685f5f9
commit 93e8996b52
3 changed files with 16 additions and 5 deletions

View File

@ -55,8 +55,10 @@ public class GenericWeatherReceiver extends BroadcastReceiver {
weatherSpec.currentCondition = safelyGet(weatherJson, String.class, "currentCondition", ""); weatherSpec.currentCondition = safelyGet(weatherJson, String.class, "currentCondition", "");
weatherSpec.currentConditionCode = safelyGet(weatherJson, Integer.class, "currentConditionCode", 0); weatherSpec.currentConditionCode = safelyGet(weatherJson, Integer.class, "currentConditionCode", 0);
weatherSpec.currentHumidity = safelyGet(weatherJson, Integer.class, "currentHumidity", 0); weatherSpec.currentHumidity = safelyGet(weatherJson, Integer.class, "currentHumidity", 0);
weatherSpec.windSpeed = safelyGet(weatherJson, Float.class, "windSpeed", 0f); weatherSpec.windSpeed = safelyGet(weatherJson, Number.class, "windSpeed", 0d).floatValue();
weatherSpec.windDirection = safelyGet(weatherJson, Integer.class, "windDirection", 0); weatherSpec.windDirection = safelyGet(weatherJson, Integer.class, "windDirection", 0);
weatherSpec.uvIndex = safelyGet(weatherJson, Number.class, "uvIndex", 0d).floatValue();
weatherSpec.precipProbability = safelyGet(weatherJson, Integer.class, "precipProbability", 0);
if (weatherJson.has("forecasts")) { if (weatherJson.has("forecasts")) {
JSONArray forecastArray = weatherJson.getJSONArray("forecasts"); JSONArray forecastArray = weatherJson.getJSONArray("forecasts");

View File

@ -38,7 +38,7 @@ public class WeatherSpec implements Parcelable, Serializable {
return new WeatherSpec[size]; return new WeatherSpec[size];
} }
}; };
public static final int VERSION = 2; public static final int VERSION = 3;
private static final long serialVersionUID = VERSION; private static final long serialVersionUID = VERSION;
public int timestamp; public int timestamp;
public String location; public String location;
@ -50,6 +50,8 @@ public class WeatherSpec implements Parcelable, Serializable {
public int todayMinTemp; // kelvin public int todayMinTemp; // kelvin
public float windSpeed; // km per hour public float windSpeed; // km per hour
public int windDirection; // deg public int windDirection; // deg
public float uvIndex;
public int precipProbability; // %
public ArrayList<Forecast> forecasts = new ArrayList<>(); public ArrayList<Forecast> forecasts = new ArrayList<>();
@ -72,7 +74,7 @@ public class WeatherSpec implements Parcelable, Serializable {
protected WeatherSpec(Parcel in) { protected WeatherSpec(Parcel in) {
int version = in.readInt(); int version = in.readInt();
if (version == VERSION) { if (version >= 2) {
timestamp = in.readInt(); timestamp = in.readInt();
location = in.readString(); location = in.readString();
currentTemp = in.readInt(); currentTemp = in.readInt();
@ -85,6 +87,10 @@ public class WeatherSpec implements Parcelable, Serializable {
windDirection = in.readInt(); windDirection = in.readInt();
in.readList(forecasts, Forecast.class.getClassLoader()); in.readList(forecasts, Forecast.class.getClassLoader());
} }
if (version >= 3) {
uvIndex = in.readFloat();
precipProbability = in.readInt();
}
} }
@Override @Override
@ -106,6 +112,8 @@ public class WeatherSpec implements Parcelable, Serializable {
dest.writeFloat(windSpeed); dest.writeFloat(windSpeed);
dest.writeInt(windDirection); dest.writeInt(windDirection);
dest.writeList(forecasts); dest.writeList(forecasts);
dest.writeFloat(uvIndex);
dest.writeInt(precipProbability);
} }
public static class Forecast implements Parcelable, Serializable { public static class Forecast implements Parcelable, Serializable {

View File

@ -1460,7 +1460,6 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
); );
} }
JSONObject forecastResponseObject = new JSONObject() JSONObject forecastResponseObject = new JSONObject()
.put("res", new JSONObject() .put("res", new JSONObject()
.put("id", 0) .put("id", 0)
@ -1473,7 +1472,9 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
.put("temp", weatherSpec.currentTemp - 273) .put("temp", weatherSpec.currentTemp - 273)
.put("high", weatherSpec.todayMaxTemp - 273) .put("high", weatherSpec.todayMaxTemp - 273)
.put("low", weatherSpec.todayMinTemp - 273) .put("low", weatherSpec.todayMinTemp - 273)
.put("rain", 0) .put("rain", weatherSpec.precipProbability)
.put("uv", Math.round(weatherSpec.uvIndex))
.put("message", weatherSpec.currentCondition)
.put("cond_id", getIconForConditionCode(weatherSpec.currentConditionCode, false)) // FIXME do not assume daylight .put("cond_id", getIconForConditionCode(weatherSpec.currentConditionCode, false)) // FIXME do not assume daylight
.put("forecast_day", forecastDayArray) .put("forecast_day", forecastDayArray)
.put("forecast_week", forecastWeekArray) .put("forecast_week", forecastWeekArray)