- Small fix in case that saved date is invalid (shouldn't be)
This commit is contained in:
parent
9a1377fd78
commit
f544f19a02
|
@ -1,4 +1,3 @@
|
|||
|
||||
package info.nightscout.androidaps.plugins.general.overview.notifications;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -86,6 +85,7 @@ public class Notification {
|
|||
|
||||
public NSAlarm nsAlarm = null;
|
||||
public Integer soundId = null;
|
||||
|
||||
public Notification() {
|
||||
}
|
||||
|
||||
|
@ -199,10 +199,10 @@ public class Notification {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean isAlarmForStaleData(){
|
||||
public static boolean isAlarmForStaleData() {
|
||||
long snoozedTo = SP.getLong("snoozedTo", 0L);
|
||||
if(snoozedTo != 0L){
|
||||
if(System.currentTimeMillis() < SP.getLong("snoozedTo", 0L)) {
|
||||
if (snoozedTo != 0L) {
|
||||
if (System.currentTimeMillis() < SP.getLong("snoozedTo", 0L)) {
|
||||
//log.debug("Alarm is snoozed for next "+(SP.getLong("snoozedTo", 0L)-System.currentTimeMillis())/1000+" seconds");
|
||||
return false;
|
||||
}
|
||||
|
@ -218,12 +218,12 @@ public class Notification {
|
|||
//log.debug("bgReadingAgoMin value is:"+bgReadingAgoMin);
|
||||
//log.debug("Stale alarm snoozed to: "+(System.currentTimeMillis() - snoozedTo)/60000L);
|
||||
Double threshold = NSSettingsStatus.getInstance().getThreshold("alarmTimeagoWarnMins");
|
||||
//log.debug("OpenAPS Alerts enabled: "+openAPSEnabledAlerts);
|
||||
// if no thresshold from Ns get it loccally
|
||||
if(threshold == null) threshold = SP.getDouble(R.string.key_nsalarm_staledatavalue,15D);
|
||||
// No threshold of OpenAPS Alarm so using the one for BG
|
||||
// Added OpenAPSEnabledAlerts to alarm check
|
||||
if((bgReadingAgoMin > threshold && SP.getBoolean(R.string.key_nsalarm_staledata, false))||(bgReadingAgoMin > threshold && openAPSEnabledAlerts)){
|
||||
//log.debug("OpenAPS Alerts enabled: "+openAPSEnabledAlerts);
|
||||
// if no thresshold from Ns get it loccally
|
||||
if (threshold == null) threshold = SP.getDouble(R.string.key_nsalarm_staledatavalue, 15D);
|
||||
// No threshold of OpenAPS Alarm so using the one for BG
|
||||
// Added OpenAPSEnabledAlerts to alarm check
|
||||
if ((bgReadingAgoMin > threshold && SP.getBoolean(R.string.key_nsalarm_staledata, false)) || (bgReadingAgoMin > threshold && openAPSEnabledAlerts)) {
|
||||
return true;
|
||||
}
|
||||
//snoozing for threshold
|
||||
|
|
|
@ -49,7 +49,7 @@ public class DateTimeUtil {
|
|||
return new LocalDateTime(year, month, dayOfMonth, hourOfDay, minute, second);
|
||||
} catch (Exception ex) {
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
LOG.error("Error creating LocalDateTime from values [atechDateTime=%d, year=%d, month=%d, day=%d, hour=%d, minute=%d, second=%d]", atechDateTime, year, month, dayOfMonth, hourOfDay, minute, second);
|
||||
LOG.error("Error creating LocalDateTime from values [atechDateTime={}, year={}, month={}, day={}, hour={}, minute={}, second={}]. Exception: {}", atechDateTime, year, month, dayOfMonth, hourOfDay, minute, second, ex.getMessage());
|
||||
//return null;
|
||||
throw ex;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,9 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -1102,7 +1104,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
if (isLoggingEnabled())
|
||||
LOG.debug(getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntry: null");
|
||||
|
||||
Long lastPumpHistoryEntryTime = SP.getLong(MedtronicConst.Statistics.LastPumpHistoryEntry, 0L);
|
||||
Long lastPumpHistoryEntryTime = getLastPumpEntryTime();
|
||||
|
||||
LocalDateTime timeMinus36h = new LocalDateTime();
|
||||
timeMinus36h = timeMinus36h.minusHours(36);
|
||||
|
@ -1197,6 +1199,26 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
}
|
||||
|
||||
private Long getLastPumpEntryTime() {
|
||||
Long lastPumpEntryTime = SP.getLong(MedtronicConst.Statistics.LastPumpHistoryEntry, 0L);
|
||||
|
||||
try {
|
||||
LocalDateTime localDateTime = DateTimeUtil.toLocalDateTime(lastPumpEntryTime);
|
||||
|
||||
if (localDateTime.getYear() != (new GregorianCalendar().get(Calendar.YEAR))) {
|
||||
LOG.warn("Saved LastPumpHistoryEntry was invalid. Year was not the same.");
|
||||
return 0L;
|
||||
}
|
||||
|
||||
return lastPumpEntryTime;
|
||||
|
||||
} catch (Exception ex) {
|
||||
LOG.warn("Saved LastPumpHistoryEntry was invalid.");
|
||||
return 0L;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void scheduleNextRefresh(MedtronicStatusRefreshType refreshType) {
|
||||
scheduleNextRefresh(refreshType, 0);
|
||||
|
|
Loading…
Reference in a new issue