1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-29 20:15:50 +01:00

Huami: Unify recorded data fetching in HuamiSupport

This commit is contained in:
José Rebelo 2023-05-20 20:44:18 +01:00
parent 8cda2f74e8
commit 07357305cb
6 changed files with 31 additions and 43 deletions

View File

@ -515,6 +515,10 @@ public abstract class HuamiCoordinator extends AbstractBLEDeviceCoordinator {
return 22; // At least, Mi Fit still allows more return 22; // At least, Mi Fit still allows more
} }
public boolean supportsDebugLogs() {
return true;
}
public List<HuamiVibrationPatternNotificationType> getVibrationPatternNotificationTypes(final GBDevice device) { public List<HuamiVibrationPatternNotificationType> getVibrationPatternNotificationTypes(final GBDevice device) {
return Arrays.asList( return Arrays.asList(
HuamiVibrationPatternNotificationType.APP_ALERTS, HuamiVibrationPatternNotificationType.APP_ALERTS,

View File

@ -79,6 +79,11 @@ public class MiBand2Coordinator extends HuamiCoordinator {
return 0; return 0;
} }
@Override
public boolean supportsDebugLogs() {
return false;
}
@Override @Override
public int[] getSupportedDeviceSpecificSettings(GBDevice device) { public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
return new int[]{ return new int[]{

View File

@ -85,6 +85,11 @@ public class MiBand2HRXCoordinator extends HuamiCoordinator {
return false; return false;
} }
@Override
public boolean supportsDebugLogs() {
return false;
}
@Override @Override
public int[] getSupportedDeviceSpecificSettings(GBDevice device) { public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
return new int[]{ return new int[]{

View File

@ -333,28 +333,6 @@ public abstract class Huami2021Support extends HuamiSupport {
calendarService.deleteEvent(type, id); calendarService.deleteEvent(type, id);
} }
@Override
public void onFetchRecordedData(final int dataTypes) {
try {
// FIXME: currently only one data type supported, these are meant to be flags
switch (dataTypes) {
case RecordedDataTypes.TYPE_ACTIVITY:
new FetchActivityOperation(this).perform();
break;
case RecordedDataTypes.TYPE_GPS_TRACKS:
new FetchSportsSummaryOperation(this, 1).perform();
break;
case RecordedDataTypes.TYPE_DEBUGLOGS:
new HuamiFetchDebugLogsOperation(this).perform();
break;
default:
LOG.warn("fetching multiple data types at once is not supported yet");
}
} catch (final Exception e) {
LOG.error("Unable to fetch recorded data types {}", dataTypes, e);
}
}
@Override @Override
public void onHeartRateTest() { public void onHeartRateTest() {
// TODO onHeartRateTest - what modes? this only works sometimes // TODO onHeartRateTest - what modes? this only works sometimes

View File

@ -116,6 +116,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser; import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.model.Alarm; import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec; import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSportsSummaryOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.HuamiFetchDebugLogsOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.services.ZeppOsCannedMessagesService; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.services.ZeppOsCannedMessagesService;
import nodomain.freeyourgadget.gadgetbridge.util.calendar.CalendarEvent; import nodomain.freeyourgadget.gadgetbridge.util.calendar.CalendarEvent;
import nodomain.freeyourgadget.gadgetbridge.util.calendar.CalendarManager; import nodomain.freeyourgadget.gadgetbridge.util.calendar.CalendarManager;
@ -1640,10 +1643,21 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
@Override @Override
public void onFetchRecordedData(int dataTypes) { public void onFetchRecordedData(int dataTypes) {
final HuamiCoordinator coordinator = getCoordinator();
try { try {
// FIXME: currently only one data type supported, these are meant to be flags
if (dataTypes == RecordedDataTypes.TYPE_ACTIVITY) {
new FetchActivityOperation(this).perform(); new FetchActivityOperation(this).perform();
} catch (IOException ex) { } else if (dataTypes == RecordedDataTypes.TYPE_GPS_TRACKS && coordinator.supportsActivityTracks()) {
LOG.error("Unable to fetch activity data", ex); new FetchSportsSummaryOperation(this, 1).perform();
} else if (dataTypes == RecordedDataTypes.TYPE_DEBUGLOGS && coordinator.supportsDebugLogs()) {
new HuamiFetchDebugLogsOperation(this).perform();
} else {
LOG.warn("fetching multiple data types at once is not supported yet");
}
} catch (final IOException ex) {
LOG.error("Unable to fetch recorded data types" + dataTypes, ex);
} }
} }

View File

@ -80,24 +80,6 @@ public class AmazfitBipSupport extends HuamiSupport {
return this; return this;
} }
@Override
public void onFetchRecordedData(int dataTypes) {
try {
// FIXME: currently only one data type supported, these are meant to be flags
if (dataTypes == RecordedDataTypes.TYPE_ACTIVITY) {
new FetchActivityOperation(this).perform();
} else if (dataTypes == RecordedDataTypes.TYPE_GPS_TRACKS) {
new FetchSportsSummaryOperation(this, 1).perform();
} else if (dataTypes == RecordedDataTypes.TYPE_DEBUGLOGS) {
new HuamiFetchDebugLogsOperation(this).perform();
} else {
LOG.warn("fetching multiple data types at once is not supported yet");
}
} catch (IOException ex) {
LOG.error("Unable to fetch recorded data types" + dataTypes, ex);
}
}
@Override @Override
public void phase2Initialize(TransactionBuilder builder) { public void phase2Initialize(TransactionBuilder builder) {
super.phase2Initialize(builder); super.phase2Initialize(builder);