From 93e8996b52bf1b4c5b539832626165e3ea180b3a Mon Sep 17 00:00:00 2001 From: Enrico Brambilla Date: Mon, 5 Jun 2023 19:52:26 +0000 Subject: [PATCH] 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 Co-committed-by: Enrico Brambilla --- .../externalevents/GenericWeatherReceiver.java | 4 +++- .../gadgetbridge/model/WeatherSpec.java | 12 ++++++++++-- .../adapter/fossil_hr/FossilHRWatchAdapter.java | 5 +++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/GenericWeatherReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/GenericWeatherReceiver.java index ba76dc30e..f1899bbc5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/GenericWeatherReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/GenericWeatherReceiver.java @@ -55,8 +55,10 @@ public class GenericWeatherReceiver extends BroadcastReceiver { weatherSpec.currentCondition = safelyGet(weatherJson, String.class, "currentCondition", ""); weatherSpec.currentConditionCode = safelyGet(weatherJson, Integer.class, "currentConditionCode", 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.uvIndex = safelyGet(weatherJson, Number.class, "uvIndex", 0d).floatValue(); + weatherSpec.precipProbability = safelyGet(weatherJson, Integer.class, "precipProbability", 0); if (weatherJson.has("forecasts")) { JSONArray forecastArray = weatherJson.getJSONArray("forecasts"); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/WeatherSpec.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/WeatherSpec.java index 88d0e95ee..2e00ddef4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/WeatherSpec.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/WeatherSpec.java @@ -38,7 +38,7 @@ public class WeatherSpec implements Parcelable, Serializable { return new WeatherSpec[size]; } }; - public static final int VERSION = 2; + public static final int VERSION = 3; private static final long serialVersionUID = VERSION; public int timestamp; public String location; @@ -50,6 +50,8 @@ public class WeatherSpec implements Parcelable, Serializable { public int todayMinTemp; // kelvin public float windSpeed; // km per hour public int windDirection; // deg + public float uvIndex; + public int precipProbability; // % public ArrayList forecasts = new ArrayList<>(); @@ -72,7 +74,7 @@ public class WeatherSpec implements Parcelable, Serializable { protected WeatherSpec(Parcel in) { int version = in.readInt(); - if (version == VERSION) { + if (version >= 2) { timestamp = in.readInt(); location = in.readString(); currentTemp = in.readInt(); @@ -85,6 +87,10 @@ public class WeatherSpec implements Parcelable, Serializable { windDirection = in.readInt(); in.readList(forecasts, Forecast.class.getClassLoader()); } + if (version >= 3) { + uvIndex = in.readFloat(); + precipProbability = in.readInt(); + } } @Override @@ -106,6 +112,8 @@ public class WeatherSpec implements Parcelable, Serializable { dest.writeFloat(windSpeed); dest.writeInt(windDirection); dest.writeList(forecasts); + dest.writeFloat(uvIndex); + dest.writeInt(precipProbability); } public static class Forecast implements Parcelable, Serializable { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java index 35aaf961b..f9cc6972c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java @@ -1460,7 +1460,6 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { ); } - JSONObject forecastResponseObject = new JSONObject() .put("res", new JSONObject() .put("id", 0) @@ -1473,7 +1472,9 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { .put("temp", weatherSpec.currentTemp - 273) .put("high", weatherSpec.todayMaxTemp - 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("forecast_day", forecastDayArray) .put("forecast_week", forecastWeekArray)