From 61872b7bbdf798e153727938365748148b504763 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sat, 3 Nov 2018 20:44:30 +0100 Subject: [PATCH] Mi Band 3/Amazfit Bip/Amazfit Cor: Send Fahrenheit if units are set to imperial Closes #1315 --- CHANGELOG.md | 1 + .../huami/amazfitbip/AmazfitBipSupport.java | 36 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e42672d6..17990a54c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Pebble: Send all wearable notification actions (not only reply) * Pebble: Always allow reply action even if untested features are turned off * Amazfit Bip: Allow flashing latest gps firmware (Mili_dth.gps) +* Mi Band 3/Amazfit Bip/Amazfit Cor: Send Fahrenheit if units are set to imperial * Roidmi 3: Fix and enable support * Mi Band 3/Amazfit Bip: fix find phone crash * Prevent re-sending old notifications to the wearable diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/AmazfitBipSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/AmazfitBipSupport.java index 58d9270d3..9b4e61262 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/AmazfitBipSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/AmazfitBipSupport.java @@ -34,12 +34,15 @@ import java.util.Set; import java.util.SimpleTimeZone; import java.util.UUID; +import cyanogenmod.weather.util.WeatherUtils; import nodomain.freeyourgadget.gadgetbridge.GBApplication; +import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiWeatherConditions; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipService; +import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst; import nodomain.freeyourgadget.gadgetbridge.model.CallSpec; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; @@ -258,6 +261,8 @@ public class AmazfitBipSupport extends HuamiSupport { if (version.compareTo(new Version("0.0.8.74")) >= 0) { supportsConditionString = true; } + + MiBandConst.DistanceUnit unit = HuamiCoordinator.getDistanceUnit(); int tz_offset_hours = SimpleTimeZone.getDefault().getOffset(weatherSpec.timestamp * 1000L) / (1000 * 60 * 60); try { TransactionBuilder builder; @@ -276,7 +281,12 @@ public class AmazfitBipSupport extends HuamiSupport { buf.putInt(weatherSpec.timestamp); buf.put((byte) (tz_offset_hours * 4)); buf.put(condition); - buf.put((byte) (weatherSpec.currentTemp - 273)); + + int currentTemp = weatherSpec.currentTemp - 273; + if (unit == MiBandConst.DistanceUnit.IMPERIAL) { + currentTemp = (int) WeatherUtils.celsiusToFahrenheit(currentTemp); + } + buf.put((byte) currentTemp); if (supportsConditionString) { buf.put(weatherSpec.currentCondition.getBytes()); @@ -354,8 +364,16 @@ public class AmazfitBipSupport extends HuamiSupport { byte condition = HuamiWeatherConditions.mapToAmazfitBipWeatherCode(weatherSpec.currentConditionCode); buf.put(condition); buf.put(condition); - buf.put((byte) (weatherSpec.todayMaxTemp - 273)); - buf.put((byte) (weatherSpec.todayMinTemp - 273)); + + int todayMaxTemp = weatherSpec.todayMaxTemp - 273; + int todayMinTemp = weatherSpec.todayMinTemp - 273; + if (unit == MiBandConst.DistanceUnit.IMPERIAL) { + todayMaxTemp = (int) WeatherUtils.celsiusToFahrenheit(todayMaxTemp); + todayMinTemp = (int) WeatherUtils.celsiusToFahrenheit(todayMinTemp); + } + buf.put((byte) todayMaxTemp); + buf.put((byte) todayMinTemp); + if (supportsConditionString) { buf.put(weatherSpec.currentCondition.getBytes()); buf.put((byte) 0); @@ -365,8 +383,16 @@ public class AmazfitBipSupport extends HuamiSupport { condition = HuamiWeatherConditions.mapToAmazfitBipWeatherCode(forecast.conditionCode); buf.put(condition); buf.put(condition); - buf.put((byte) (forecast.maxTemp - 273)); - buf.put((byte) (forecast.minTemp - 273)); + + int forecastMaxTemp = forecast.maxTemp - 273; + int forecastMinTemp = forecast.minTemp - 273; + if (unit == MiBandConst.DistanceUnit.IMPERIAL) { + forecastMaxTemp = (int) WeatherUtils.celsiusToFahrenheit(forecastMaxTemp); + forecastMinTemp = (int) WeatherUtils.celsiusToFahrenheit(forecastMinTemp); + } + buf.put((byte) forecastMaxTemp); + buf.put((byte) forecastMinTemp); + if (supportsConditionString) { buf.put(Weather.getConditionString(forecast.conditionCode).getBytes()); buf.put((byte) 0);