Merge pull request #126 from 0pen-dash/avereha/i8n-expiration

multiple fixes
This commit is contained in:
Andrei Vereha 2021-09-21 22:13:59 +02:00 committed by GitHub
commit fdee9e8862
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 94 additions and 26 deletions

View file

@ -177,7 +177,7 @@ class MessageIO(
}
BleCommandSuccess -> {
if (index == packets.size-1)
if (index == packets.size - 1)
MessageSendSuccess
else
MessageSendErrorSending("Received SUCCESS before sending all the data. $index")

View file

@ -100,22 +100,23 @@ class ProgramBasalCommand private constructor(
}
override fun buildCommand(): ProgramBasalCommand {
requireNotNull(basalProgram) { "basalProgram can not be null" }
requireNotNull(programReminder) { "programReminder can not be null" }
requireNotNull(currentTime) { "currentTime can not be null" }
val pulsesPerSlot = ProgramBasalUtil.mapBasalProgramToPulsesPerSlot(basalProgram!!)
val currentSlot = ProgramBasalUtil.calculateCurrentSlot(pulsesPerSlot, currentTime)
val program = requireNotNull(basalProgram) { "basalProgram can not be null" }
val reminder = requireNotNull(programReminder) { "programReminder can not be null" }
val time = requireNotNull(currentTime) { "currentTime can not be null" }
val pulsesPerSlot = ProgramBasalUtil.mapBasalProgramToPulsesPerSlot(program)
val currentSlot = ProgramBasalUtil.calculateCurrentSlot(pulsesPerSlot, time)
val checksum = ProgramBasalUtil.calculateChecksum(pulsesPerSlot, currentSlot)
val longInsulinProgramElements: List<BasalInsulinProgramElement> =
mapTenthPulsesPerSlotToLongInsulinProgramElements(
ProgramBasalUtil.mapBasalProgramToTenthPulsesPerSlot(basalProgram!!)
ProgramBasalUtil.mapBasalProgramToTenthPulsesPerSlot(program)
)
val shortInsulinProgramElements = ProgramBasalUtil.mapPulsesPerSlotToShortInsulinProgramElements(
pulsesPerSlot
)
val currentBasalInsulinProgramElement = ProgramBasalUtil.calculateCurrentLongInsulinProgramElement(
longInsulinProgramElements,
currentTime
time
)
val interlockCommand = ProgramInsulinCommand(
uniqueId!!, sequenceNumber!!, multiCommandFlag, nonce!!,
@ -128,7 +129,7 @@ class ProgramBasalCommand private constructor(
sequenceNumber!!,
multiCommandFlag,
longInsulinProgramElements,
programReminder!!,
reminder,
currentBasalInsulinProgramElement.index,
currentBasalInsulinProgramElement.remainingTenthPulses,
currentBasalInsulinProgramElement.delayUntilNextTenthPulseInUsec

View file

@ -189,7 +189,7 @@ object ProgramBasalUtil {
return pulsesPerSlot
}
fun calculateCurrentSlot(pulsesPerSlot: ShortArray?, currentTime: Date?): CurrentSlot {
fun calculateCurrentSlot(pulsesPerSlot: ShortArray?, currentTime: Date): CurrentSlot {
val instance = Calendar.getInstance()
instance.time = currentTime
val hourOfDay = instance[Calendar.HOUR_OF_DAY]
@ -205,7 +205,7 @@ object ProgramBasalUtil {
fun calculateCurrentLongInsulinProgramElement(
elements: List<BasalInsulinProgramElement>,
currentTime: Date?
currentTime: Date
): CurrentBasalInsulinProgramElement {
val instance = Calendar.getInstance()
instance.time = currentTime

View file

@ -241,6 +241,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
.plusHours(podLifeInHours.toLong())
.minusMinutes(minutesSinceActivation.toLong())
.minus(Duration.ofMillis(System.currentTimeMillis() - lastUpdatedSystem))
.minusHours(8)
}
return null
}

View file

@ -13,6 +13,7 @@ import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.events.EventPumpStatusChanged
import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
@ -30,6 +31,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
import info.nightscout.androidaps.plugins.pump.omnipod.dash.databinding.OmnipodDashOverviewBinding
import info.nightscout.androidaps.plugins.pump.omnipod.dash.databinding.OmnipodDashOverviewBluetoothStatusBinding
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ActivationProgress
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertType
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.queue.events.EventQueueChanged
@ -205,6 +207,16 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
},
fabricPrivacy::logException
)
disposables += rxBus
.toObservable(EventPumpStatusChanged::class.java)
.observeOn(aapsSchedulers.main)
.subscribe(
{
updateBluetoothConnectionStatus(it)
},
fabricPrivacy::logException
)
updateUi()
}
@ -230,18 +242,18 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
updateQueueStatus()
}
private fun updateBluetoothConnectionStatus(event: EventPumpStatusChanged) {
var status = event.getStatus(resourceHelper)
if (status.isEmpty()) {
status = resourceHelper.gs(R.string.disconnected)
}
bluetoothStatusBinding.omnipodDashBluetoothStatus.text = status
}
private fun updateBluetoothStatus() {
bluetoothStatusBinding.omnipodDashBluetoothAddress.text = podStateManager.bluetoothAddress
?: PLACEHOLDER
bluetoothStatusBinding.omnipodDashBluetoothStatus.text =
when (podStateManager.bluetoothConnectionState) {
OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTED ->
"{fa-bluetooth}"
OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED ->
"{fa-bluetooth-b}"
OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING ->
"{fa-bluetooth-b spin}"
}
val connectionSuccessPercentage = podStateManager.connectionSuccessRatio() * 100
val successPercentageString = String.format("%.2f %%", connectionSuccessPercentage)
@ -389,7 +401,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
}
podInfoBinding.podActiveAlerts.text = podStateManager.activeAlerts?.let { it ->
it.joinToString(",") { it.toString() }
it.joinToString(System.lineSeparator()) { t -> translatedActiveAlert(t) }
} ?: PLACEHOLDER
}
@ -402,6 +414,24 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
}
}
private fun translatedActiveAlert(alert: AlertType): String {
val id = when (alert) {
AlertType.LOW_RESERVOIR ->
R.string.omnipod_common_alert_low_reservoir
AlertType.EXPIRATION ->
R.string.omnipod_common_alert_expiration_advisory
AlertType.EXPIRATION_IMMINENT ->
R.string.omnipod_common_alert_expiration
AlertType.USER_SET_EXPIRATION ->
R.string.omnipod_common_alert_expiration_advisory
AlertType.AUTO_OFF ->
R.string.omnipod_common_alert_shutdown_imminent
else ->
R.string.omnipod_common_alert_unknown_alert
}
return resourceHelper.gs(id)
}
private fun updateLastConnection() {
if (podStateManager.isUniqueIdSet) {
podInfoBinding.lastConnection.text = readableDuration(

View file

@ -10,6 +10,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertTrigger
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.Single
import io.reactivex.rxkotlin.subscribeBy
@ -21,6 +23,7 @@ class DashInitializePodViewModel @Inject constructor(
logger: AAPSLogger,
private val sp: SP,
private val podStateManager: OmnipodDashPodStateManager,
private val resourceHelper: ResourceHelper
) : InitializePodViewModel(injector, logger) {
override fun isPodInAlarm(): Boolean = false // TODO
@ -37,7 +40,7 @@ class DashInitializePodViewModel @Inject constructor(
} else
null
val disposable = omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy(
omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy(
onNext = { podEvent ->
logger.debug(
LTag.PUMP,
@ -46,7 +49,11 @@ class DashInitializePodViewModel @Inject constructor(
},
onError = { throwable ->
logger.error(LTag.PUMP, "Error in Pod activation part 1", throwable)
source.onSuccess(PumpEnactResult(injector).success(false).comment(throwable.toString()))
source.onSuccess(
PumpEnactResult(injector)
.success(false)
.comment(I8n.textFromException(throwable, resourceHelper))
)
},
onComplete = {
logger.debug("Pod activation part 1 completed")

View file

@ -16,7 +16,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activati
import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.Single
import io.reactivex.rxkotlin.subscribeBy
@ -29,6 +31,7 @@ class DashInsertCannulaViewModel @Inject constructor(
private val podStateManager: OmnipodDashPodStateManager,
private val rxBus: RxBusWrapper,
private val sp: SP,
private val resourceHelper: ResourceHelper,
injector: HasAndroidInjector,
logger: AAPSLogger
@ -60,7 +63,7 @@ class DashInsertCannulaViewModel @Inject constructor(
else
null
val disposable = omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy(
omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy(
onNext = { podEvent ->
logger.debug(
LTag.PUMP,
@ -69,7 +72,7 @@ class DashInsertCannulaViewModel @Inject constructor(
},
onError = { throwable ->
logger.error(LTag.PUMP, "Error in Pod activation part 2", throwable)
source.onSuccess(PumpEnactResult(injector).success(false).comment(throwable.toString()))
source.onSuccess(PumpEnactResult(injector).success(false).comment(I8n.textFromException(throwable, resourceHelper)))
},
onComplete = {
logger.debug("Pod activation part 2 completed")

View file

@ -0,0 +1,21 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.util
import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.FailedToConnectException
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.ScanException
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.ScanFailFoundTooManyException
import info.nightscout.androidaps.utils.resources.ResourceHelper
class I8n {
companion object {
fun textFromException(exception: Throwable, rs: ResourceHelper): String {
return when (exception) {
is FailedToConnectException -> rs.gs(R.string.omnipod_dash_failed_to_connect)
is ScanFailFoundTooManyException -> rs.gs(R.string.omnipod_dash_found_too_many_pods)
is ScanException -> rs.gs(R.string.omnipod_dash_scan_failed)
else ->
rs.gs(R.string.omnipod_dash_generic_error, exception.toString())
}
}
}
}

View file

@ -73,7 +73,6 @@
android:gravity="start"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:text="{fa-bluetooth-b} "
android:textSize="14sp"
tools:ignore="HardcodedText" />
</LinearLayout>

View file

@ -24,4 +24,10 @@
<string name="key_common_preferences_category_other_settings" translatable="false">common_preferences_category_other</string>
<string name="key_omnipod_common_notification_delivery_suspended_sound_enabled">AAPS.Omnipod.notification_delivery_suspended_sound_enabled</string>
<string name="omnipod_common_preferences_notification_delivery_suspended_sound_enabled">Sound when delivery suspended notification enabled</string>
<!-- Exceptions -->
<string name="omnipod_dash_failed_to_connect">Failed to connect to pod</string>
<string name="omnipod_dash_found_too_many_pods">Found too many pods for activation</string>
<string name="omnipod_dash_scan_failed">Could not find an available pod for activation</string>
<string name="omnipod_dash_generic_error">Generic error: %1$s</string>
</resources>