Skip to content

Commit 340dce4

Browse files
authored
Merge pull request #4047 from Navid200/Navid_2025_06_10
Session start time update for alt (corrects Nightscout SAGE)
2 parents 41351cc + 6b43eff commit 340dce4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

app/src/main/java/com/eveningoutpost/dexdrip/models/Treatments.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.activeandroid.util.SQLiteUtils;
1919
import com.eveningoutpost.dexdrip.GcmActivity;
2020
import com.eveningoutpost.dexdrip.Home;
21+
import com.eveningoutpost.dexdrip.g5model.DexSessionKeeper;
2122
import com.eveningoutpost.dexdrip.models.UserError.Log;
2223
import com.eveningoutpost.dexdrip.R;
2324
import com.eveningoutpost.dexdrip.services.SyncService;
@@ -58,7 +59,6 @@
5859
import static com.eveningoutpost.dexdrip.models.JoH.msSince;
5960
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS;
6061
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS;
61-
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
6262
import static java.lang.StrictMath.abs;
6363
import static com.eveningoutpost.dexdrip.models.JoH.emptyString;
6464

@@ -449,6 +449,15 @@ public static void sensorStartIfNeeded() {
449449
}
450450
}
451451

452+
public static void sensorUpdateStartTimeIfNeeded() {
453+
val lastSensorStart = Treatments.lastEventTypeFromXdrip(Treatments.SENSOR_START_EVENT_TYPE);
454+
long localStartedAt = lastSensorStart.timestamp; // When the xDrip local session started
455+
long dexStartedAt = DexSessionKeeper.getStart(); // When the current session on the transmitter started
456+
if (dexStartedAt > 0 && !(dexStartedAt - localStartedAt < MINUTE_IN_MS * 5)) { // If the start time of the local session is more than 5 minutes older than the one on the transmitter
457+
Treatments.sensorStart(dexStartedAt, "Start time updated");
458+
}
459+
}
460+
452461
private static void pushTreatmentSync(Treatments treatment) {
453462
pushTreatmentSync(treatment, true, null); // new entry by default
454463
}

app/src/main/java/com/eveningoutpost/dexdrip/services/Ob1G5CollectionService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,10 @@ public static void processCalibrationState(final CalibrationState state) {
19451945
updateG5State(needs_calibration, was_needing_calibration, NEEDING_CALIBRATION);
19461946
updateG5State(is_started, was_started, IS_STARTED);
19471947
updateG5State(is_failed, was_failed, IS_FAILED);
1948+
1949+
if (is_started && shortTxId() && JoH.pratelimit("update_alternate_dex_session_start_time", 60 * 60)) { // Once an hour if there is a local session
1950+
Treatments.sensorUpdateStartTimeIfNeeded();
1951+
}
19481952
}
19491953

19501954

0 commit comments

Comments
 (0)