From 6d28b8232bf1d5d9135c980218824c1acad271a3 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 25 Aug 2017 23:35:16 +0200 Subject: [PATCH] Amazift Bip: fix weather on FW 0.0.8.74, support condition text --- .../AmazfitBipWeatherConditions.java | 31 +------------------ .../devices/amazfitbip/AmazfitBipSupport.java | 26 ++++++++++++++-- .../gadgetbridge/util/Version.java | 4 ++- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/amazfitbip/AmazfitBipWeatherConditions.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/amazfitbip/AmazfitBipWeatherConditions.java index 0284c9bf..02dd5b9a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/amazfitbip/AmazfitBipWeatherConditions.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/amazfitbip/AmazfitBipWeatherConditions.java @@ -157,33 +157,4 @@ public class AmazfitBipWeatherConditions { return 0; } } - - public static String mapToOpenWeatherMapIcon(int openWeatherMapCondition) { - //see https://openweathermap.org/weather-conditions - String condition = "02d"; //generic "variable" icon - - if (openWeatherMapCondition >= 200 && openWeatherMapCondition < 300) { - condition = "11d"; - } else if (openWeatherMapCondition >= 300 && openWeatherMapCondition < 500) { - condition = "09d"; - } else if (openWeatherMapCondition >= 500 && openWeatherMapCondition < 510) { - condition = "10d"; - } else if (openWeatherMapCondition >= 511 && openWeatherMapCondition < 600) { - condition = "09d"; - } else if (openWeatherMapCondition >= 600 && openWeatherMapCondition < 700) { - condition = "13d"; - } else if (openWeatherMapCondition >= 700 && openWeatherMapCondition < 800) { - condition = "50d"; - } else if (openWeatherMapCondition == 800) { - condition = "01d"; //TODO: night? - } else if (openWeatherMapCondition == 801) { - condition = "02d"; //TODO: night? - } else if (openWeatherMapCondition == 802) { - condition = "03d"; //TODO: night? - } else if (openWeatherMapCondition == 803 || openWeatherMapCondition == 804) { - condition = "04d"; //TODO: night? - } - - return condition; - } -} +} \ No newline at end of file diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java index c0cfa653..080259a9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java @@ -43,6 +43,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationS import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support; import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; +import nodomain.freeyourgadget.gadgetbridge.util.Version; public class AmazfitBipSupport extends MiBand2Support { @@ -129,8 +130,23 @@ public class AmazfitBipSupport extends MiBand2Support { public void onSendWeather(WeatherSpec weatherSpec) { try { TransactionBuilder builder = performInitialized("Sending weather forecast"); + Version version = new Version(gbDevice.getFirmwareVersion()); + + boolean supportsConditionString = false; + if (version.compareTo(new Version("0.0.8.74")) >= 0) { + supportsConditionString = true; + } + final byte NR_DAYS = 2; - ByteBuffer buf = ByteBuffer.allocate(7 + 4 * NR_DAYS); + int bytesPerDay = 4; + int conditionsLength = 0; + if (supportsConditionString) { + bytesPerDay = 5; + conditionsLength = weatherSpec.currentCondition.getBytes().length; + } + int length = 7 + bytesPerDay * NR_DAYS + conditionsLength; + ByteBuffer buf = ByteBuffer.allocate(length); + buf.order(ByteOrder.LITTLE_ENDIAN); buf.put((byte) 1); buf.putInt(weatherSpec.timestamp); @@ -143,13 +159,19 @@ public class AmazfitBipSupport extends MiBand2Support { buf.put(condition); buf.put((byte) (weatherSpec.todayMaxTemp - 273)); buf.put((byte) (weatherSpec.todayMinTemp - 273)); - + if (supportsConditionString) { + buf.put(weatherSpec.currentCondition.getBytes()); + buf.put((byte) 0); // + } condition = AmazfitBipWeatherConditions.mapToAmazfitBipWeatherCode(weatherSpec.tomorrowConditionCode); buf.put(condition); buf.put(condition); buf.put((byte) (weatherSpec.tomorrowMaxTemp - 273)); buf.put((byte) (weatherSpec.tomorrowMinTemp - 273)); + if (supportsConditionString) { + buf.put((byte) 0); // not yet in weatherspec + } builder.write(getCharacteristic(AmazfitBipService.UUID_CHARACTERISTIC_WEATHER), buf.array()); builder.queue(getQueue()); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/Version.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/Version.java index df0efe2c..82a397f7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/Version.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/Version.java @@ -28,7 +28,9 @@ public class Version implements Comparable { public Version(String version) { if(version == null) throw new IllegalArgumentException("Version can not be null"); - if(!version.matches("[0-9]+(\\.[0-9]+)*")) + + version = version.trim(); + if (!version.matches("[0-9]+(\\.[0-9]+)*")) throw new IllegalArgumentException("Invalid version format"); this.version = version; }