mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 18:45:49 +01:00
Zepp OS: Fix fetching workouts shorter than 1 minute
Since GB would always round down the time precision to the minute, workouts shorter than 1 minute would be fetched over and over again.
This commit is contained in:
parent
a717fd1db2
commit
1335f0bd86
@ -106,6 +106,7 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||||
@ -875,6 +876,18 @@ public abstract class Huami2021Support extends HuamiSupport {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getTimeBytes(final Calendar calendar, final TimeUnit precision) {
|
||||||
|
final byte[] bytes = BLETypeConversions.shortCalendarToRawBytes(calendar);
|
||||||
|
|
||||||
|
if (precision != TimeUnit.MINUTES && precision != TimeUnit.SECONDS) {
|
||||||
|
throw new IllegalArgumentException("Unsupported precision, only MINUTES and SECONDS are supported");
|
||||||
|
}
|
||||||
|
final byte seconds = precision == TimeUnit.SECONDS ? fromUint8(calendar.get(Calendar.SECOND)) : 0;
|
||||||
|
final byte tz = BLETypeConversions.mapTimeZone(calendar, BLETypeConversions.TZ_FLAG_INCLUDE_DST_IN_TZ);
|
||||||
|
return BLETypeConversions.join(bytes, new byte[]{seconds, tz});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Huami2021Support setCurrentTimeWithService(TransactionBuilder builder) {
|
public Huami2021Support setCurrentTimeWithService(TransactionBuilder builder) {
|
||||||
// It seems that the format sent to the Current Time characteristic changed in newer devices
|
// It seems that the format sent to the Current Time characteristic changed in newer devices
|
||||||
|
@ -162,10 +162,11 @@ public abstract class AbstractFetchOperation extends AbstractHuamiOperation {
|
|||||||
|
|
||||||
protected void startFetching(TransactionBuilder builder, byte fetchType, GregorianCalendar sinceWhen) {
|
protected void startFetching(TransactionBuilder builder, byte fetchType, GregorianCalendar sinceWhen) {
|
||||||
final String taskName = StringUtils.ensureNotNull(builder.getTaskName());
|
final String taskName = StringUtils.ensureNotNull(builder.getTaskName());
|
||||||
|
final boolean isHuami2021 = getSupport() instanceof Huami2021Support;
|
||||||
byte[] fetchBytes = BLETypeConversions.join(new byte[]{
|
byte[] fetchBytes = BLETypeConversions.join(new byte[]{
|
||||||
HuamiService.COMMAND_ACTIVITY_DATA_START_DATE,
|
HuamiService.COMMAND_ACTIVITY_DATA_START_DATE,
|
||||||
fetchType},
|
fetchType},
|
||||||
getSupport().getTimeBytes(sinceWhen, TimeUnit.MINUTES));
|
getSupport().getTimeBytes(sinceWhen, isHuami2021 ? TimeUnit.SECONDS : TimeUnit.MINUTES));
|
||||||
builder.add(new AbstractGattListenerWriteAction(getQueue(), characteristicFetch, fetchBytes) {
|
builder.add(new AbstractGattListenerWriteAction(getQueue(), characteristicFetch, fetchBytes) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
protected boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
||||||
@ -175,7 +176,7 @@ public abstract class AbstractFetchOperation extends AbstractHuamiOperation {
|
|||||||
|
|
||||||
if (ArrayUtils.equals(value, HuamiService.RESPONSE_ACTIVITY_DATA_START_DATE_SUCCESS, 0)) {
|
if (ArrayUtils.equals(value, HuamiService.RESPONSE_ACTIVITY_DATA_START_DATE_SUCCESS, 0)) {
|
||||||
handleActivityMetadata(value);
|
handleActivityMetadata(value);
|
||||||
if (expectedDataLength == 0 && getSupport() instanceof Huami2021Support) {
|
if (expectedDataLength == 0 && isHuami2021) {
|
||||||
// Nothing to receive, if we try to fetch data it will fail
|
// Nothing to receive, if we try to fetch data it will fail
|
||||||
sendAck2021(true);
|
sendAck2021(true);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user