From fbe727644e42960bca4284b267044aa25bdfe4e6 Mon Sep 17 00:00:00 2001 From: "Martin.JM" Date: Mon, 29 Jul 2024 21:55:51 +0200 Subject: [PATCH] Huawei: Add UV index support Also adds "0.0 to 15.0" comment to the weatherSpec uvIndex. --- .../gadgetbridge/devices/huawei/HuaweiCoordinator.java | 4 ++++ .../gadgetbridge/devices/huawei/packets/Weather.java | 7 ++++++- .../freeyourgadget/gadgetbridge/model/WeatherSpec.java | 6 +++--- .../service/devices/huawei/HuaweiSupportProvider.java | 1 + .../devices/huawei/requests/SendWeatherCurrentRequest.java | 1 + 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCoordinator.java index 156e5d9a5..b6c6053fc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCoordinator.java @@ -423,6 +423,10 @@ public class HuaweiCoordinator { return supportsCommandForService(0x0f, 0x0b); } + public boolean supportsWeatherUvIndex() { + return supportsExpandCapability(0x2f); + } + public boolean supportsWorkouts() { return supportsCommandForService(0x17, 0x01); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/Weather.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/Weather.java index f03acfca4..34f7d0877 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/Weather.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/Weather.java @@ -45,6 +45,9 @@ public class Weather { // WeatherSunMoonSupport public boolean sunRiseSetSupported = false; public boolean moonPhaseSupported = false; + + // ExpandCapabilityRequest + public boolean uvIndexSupported = false; } public enum WeatherIcon { @@ -358,6 +361,7 @@ public class Weather { HuaweiTemperatureFormat temperatureUnit, Short airQualityIndex, Integer observationTime, + Float uvIndex, String sourceName ) { super(paramsProvider); @@ -411,7 +415,8 @@ public class Weather { this.tlv.put(0x0c, observationTime); if (sourceName != null && settings.sourceSupported) this.tlv.put(0x0e, sourceName); - this.tlv.put(0x0f, (byte) 0); + if (uvIndex != null && settings.uvIndexSupported) + this.tlv.put(0x0f, uvIndex.byteValue()); this.isEncrypted = true; this.complete = true; 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 2cec3ff31..10c6c8376 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/WeatherSpec.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/WeatherSpec.java @@ -54,7 +54,7 @@ public class WeatherSpec implements Parcelable, Serializable { public int todayMinTemp; // kelvin public float windSpeed; // km per hour public int windDirection; // deg - public float uvIndex; + public float uvIndex; // 0.0 to 15.0 public int precipProbability; // % public int dewPoint; // kelvin public float pressure; // mb @@ -357,7 +357,7 @@ public class WeatherSpec implements Parcelable, Serializable { public int humidity; public float windSpeed; // km per hour public int windDirection; // deg - public float uvIndex; + public float uvIndex; // 0.0 to 15.0 public int precipProbability; // % public int sunRise; public int sunSet; @@ -438,7 +438,7 @@ public class WeatherSpec implements Parcelable, Serializable { public int humidity; public float windSpeed; // km per hour public int windDirection; // deg - public float uvIndex; + public float uvIndex; // 0.0 to 15.0 public int precipProbability; // % public Hourly() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java index 87ddc3a89..5a37b22aa 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java @@ -1877,6 +1877,7 @@ public class HuaweiSupportProvider { WeatherSpec weatherSpec = weatherSpecs.get(0); Weather.Settings weatherSettings = new Weather.Settings(); + weatherSettings.uvIndexSupported = getHuaweiCoordinator().supportsWeatherUvIndex(); SendWeatherStartRequest weatherStartRequest = new SendWeatherStartRequest(this, weatherSettings); try { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendWeatherCurrentRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendWeatherCurrentRequest.java index 3889ddadd..9efc52c56 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendWeatherCurrentRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SendWeatherCurrentRequest.java @@ -66,6 +66,7 @@ public class SendWeatherCurrentRequest extends Request { temperatureFormat, aqi, weatherSpec.timestamp, + weatherSpec.uvIndex, "Gadgetbridge" ).serialize(); } catch (HuaweiPacket.CryptoException e) {