Amazift Bip: fix weather on FW 0.0.8.74, support condition text
parent
8aebf2d9d5
commit
6d28b8232b
|
@ -157,33 +157,4 @@ public class AmazfitBipWeatherConditions {
|
||||||
return 0;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -43,6 +43,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationS
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.Version;
|
||||||
|
|
||||||
public class AmazfitBipSupport extends MiBand2Support {
|
public class AmazfitBipSupport extends MiBand2Support {
|
||||||
|
|
||||||
|
@ -129,8 +130,23 @@ public class AmazfitBipSupport extends MiBand2Support {
|
||||||
public void onSendWeather(WeatherSpec weatherSpec) {
|
public void onSendWeather(WeatherSpec weatherSpec) {
|
||||||
try {
|
try {
|
||||||
TransactionBuilder builder = performInitialized("Sending weather forecast");
|
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;
|
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.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
buf.put((byte) 1);
|
buf.put((byte) 1);
|
||||||
buf.putInt(weatherSpec.timestamp);
|
buf.putInt(weatherSpec.timestamp);
|
||||||
|
@ -143,13 +159,19 @@ public class AmazfitBipSupport extends MiBand2Support {
|
||||||
buf.put(condition);
|
buf.put(condition);
|
||||||
buf.put((byte) (weatherSpec.todayMaxTemp - 273));
|
buf.put((byte) (weatherSpec.todayMaxTemp - 273));
|
||||||
buf.put((byte) (weatherSpec.todayMinTemp - 273));
|
buf.put((byte) (weatherSpec.todayMinTemp - 273));
|
||||||
|
if (supportsConditionString) {
|
||||||
|
buf.put(weatherSpec.currentCondition.getBytes());
|
||||||
|
buf.put((byte) 0); //
|
||||||
|
}
|
||||||
condition = AmazfitBipWeatherConditions.mapToAmazfitBipWeatherCode(weatherSpec.tomorrowConditionCode);
|
condition = AmazfitBipWeatherConditions.mapToAmazfitBipWeatherCode(weatherSpec.tomorrowConditionCode);
|
||||||
|
|
||||||
buf.put(condition);
|
buf.put(condition);
|
||||||
buf.put(condition);
|
buf.put(condition);
|
||||||
buf.put((byte) (weatherSpec.tomorrowMaxTemp - 273));
|
buf.put((byte) (weatherSpec.tomorrowMaxTemp - 273));
|
||||||
buf.put((byte) (weatherSpec.tomorrowMinTemp - 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.write(getCharacteristic(AmazfitBipService.UUID_CHARACTERISTIC_WEATHER), buf.array());
|
||||||
builder.queue(getQueue());
|
builder.queue(getQueue());
|
||||||
|
|
|
@ -28,7 +28,9 @@ public class Version implements Comparable<Version> {
|
||||||
public Version(String version) {
|
public Version(String version) {
|
||||||
if(version == null)
|
if(version == null)
|
||||||
throw new IllegalArgumentException("Version can not be 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");
|
throw new IllegalArgumentException("Invalid version format");
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue