fix RS timezone handling
This commit is contained in:
parent
be6c184061
commit
40c9907515
3 changed files with 23 additions and 10 deletions
|
@ -55,6 +55,8 @@ dependencies {
|
|||
|
||||
implementation "io.reactivex.rxjava2:rxandroid:${rxandroid_version}"
|
||||
|
||||
implementation 'net.danlew:android.joda:2.10.6'
|
||||
|
||||
// Graphview cannot be upgraded
|
||||
implementation "com.jjoe64:graphview:4.0.1"
|
||||
|
||||
|
|
|
@ -9,10 +9,13 @@ import info.nightscout.androidaps.logging.AAPSLogger
|
|||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.DateTimeZone
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import java.text.DecimalFormat
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
@ -60,7 +63,13 @@ class DanaPump @Inject constructor(
|
|||
}
|
||||
|
||||
fun setPumpTime(value: Long, zoneOffset: Int) {
|
||||
pumpTime = value + T.hours(zoneOffset.toLong()).msecs()
|
||||
// Store time according to timezone in phone
|
||||
val tz = DateTimeZone.getDefault()
|
||||
val instant = DateTime.now().millis
|
||||
val offsetInMilliseconds = tz.getOffset(instant).toLong()
|
||||
val offset = TimeUnit.MILLISECONDS.toHours(offsetInMilliseconds)
|
||||
pumpTime = value + T.hours(offset).msecs()
|
||||
// but save zone in pump
|
||||
this.zoneOffset = zoneOffset
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import dagger.android.HasAndroidInjector
|
|||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.activities.ErrorHelperActivity
|
||||
import info.nightscout.androidaps.dana.DanaPump
|
||||
import info.nightscout.androidaps.dana.events.EventDanaRNewStatus
|
||||
import info.nightscout.androidaps.danars.DanaRSPlugin
|
||||
import info.nightscout.androidaps.danars.R
|
||||
import info.nightscout.androidaps.danars.comm.*
|
||||
|
@ -153,12 +154,17 @@ class DanaRSService : DaggerService() {
|
|||
// initial handshake was not successful
|
||||
// de-initialize pump
|
||||
danaPump.reset()
|
||||
rxBus.send(info.nightscout.androidaps.dana.events.EventDanaRNewStatus())
|
||||
rxBus.send(EventDanaRNewStatus())
|
||||
rxBus.send(EventInitializationChanged())
|
||||
return
|
||||
}
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: $timeDiff seconds")
|
||||
if (abs(timeDiff) > 3) {
|
||||
// phone timezone
|
||||
val tz = DateTimeZone.getDefault()
|
||||
val instant = DateTime.now().millis
|
||||
val offsetInMilliseconds = tz.getOffset(instant).toLong()
|
||||
val offset = TimeUnit.MILLISECONDS.toHours(offsetInMilliseconds).toInt()
|
||||
if (abs(timeDiff) > 3 || danaPump.usingUTC && offset != danaPump.zoneOffset) {
|
||||
if (abs(timeDiff) > 60 * 60 * 1.5) {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: $timeDiff seconds - large difference")
|
||||
//If time-diff is very large, warn user until we can synchronize history readings properly
|
||||
|
@ -171,16 +177,12 @@ class DanaRSService : DaggerService() {
|
|||
|
||||
//de-initialize pump
|
||||
danaPump.reset()
|
||||
rxBus.send(info.nightscout.androidaps.dana.events.EventDanaRNewStatus())
|
||||
rxBus.send(EventDanaRNewStatus())
|
||||
rxBus.send(EventInitializationChanged())
|
||||
return
|
||||
} else {
|
||||
if (danaPump.usingUTC) {
|
||||
val tz = DateTimeZone.getDefault()
|
||||
val instant = DateTime.now().millis
|
||||
val offsetInMilliseconds = tz.getOffset(instant).toLong()
|
||||
val hours = TimeUnit.MILLISECONDS.toHours(offsetInMilliseconds).toInt()
|
||||
sendMessage(DanaRS_Packet_Option_Set_Pump_UTC_And_TimeZone(injector, DateUtil.now(), hours))
|
||||
sendMessage(DanaRS_Packet_Option_Set_Pump_UTC_And_TimeZone(injector, DateUtil.now(), offset))
|
||||
} else if (danaPump.protocol >= 6) { // can set seconds
|
||||
sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now()))
|
||||
} else {
|
||||
|
@ -195,7 +197,7 @@ class DanaRSService : DaggerService() {
|
|||
}
|
||||
}
|
||||
loadEvents()
|
||||
rxBus.send(info.nightscout.androidaps.dana.events.EventDanaRNewStatus())
|
||||
rxBus.send(EventDanaRNewStatus())
|
||||
rxBus.send(EventInitializationChanged())
|
||||
//NSUpload.uploadDeviceStatus();
|
||||
if (danaPump.dailyTotalUnits > danaPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
|
||||
|
|
Loading…
Reference in a new issue