Merge pull request #2946 from jbr7rr/medtrum-fixes
Medtrum: Add local warning for expiry
This commit is contained in:
commit
9cd258a35f
|
@ -141,6 +141,7 @@ import kotlin.math.abs
|
||||||
preprocessAlarmSettings(preferenceFragment)
|
preprocessAlarmSettings(preferenceFragment)
|
||||||
preprocessMaxInsulinSettings(preferenceFragment)
|
preprocessMaxInsulinSettings(preferenceFragment)
|
||||||
preprocessConnectionAlertSettings(preferenceFragment)
|
preprocessConnectionAlertSettings(preferenceFragment)
|
||||||
|
preprocessPumpWarningSettings(preferenceFragment)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun preprocessSerialSettings(preferenceFragment: PreferenceFragmentCompat) {
|
private fun preprocessSerialSettings(preferenceFragment: PreferenceFragmentCompat) {
|
||||||
|
@ -263,6 +264,14 @@ import kotlin.math.abs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun preprocessPumpWarningSettings(preferenceFragment: PreferenceFragmentCompat) {
|
||||||
|
val patchExpirationPref = preferenceFragment.findPreference<SwitchPreference>(rh.gs(R.string.key_patch_expiration))
|
||||||
|
val pumpWarningNotificationPref = preferenceFragment.findPreference<SwitchPreference>(rh.gs(R.string.key_pump_warning_notification))
|
||||||
|
val pumpWarningExpiryHourPref = preferenceFragment.findPreference<ValidatingEditTextPreference>(rh.gs(R.string.key_pump_warning_expiry_hour))
|
||||||
|
|
||||||
|
pumpWarningExpiryHourPref?.isEnabled = patchExpirationPref?.isChecked == true && pumpWarningNotificationPref?.isChecked == true
|
||||||
|
}
|
||||||
|
|
||||||
override fun isInitialized(): Boolean {
|
override fun isInitialized(): Boolean {
|
||||||
return medtrumPump.pumpState > MedtrumPumpState.EJECTED && medtrumPump.pumpState < MedtrumPumpState.STOPPED
|
return medtrumPump.pumpState > MedtrumPumpState.EJECTED && medtrumPump.pumpState < MedtrumPumpState.STOPPED
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,6 +288,8 @@ class MedtrumPump @Inject constructor(
|
||||||
var desiredAlarmSetting = AlarmSetting.LIGHT_VIBRATE_AND_BEEP
|
var desiredAlarmSetting = AlarmSetting.LIGHT_VIBRATE_AND_BEEP
|
||||||
var desiredHourlyMaxInsulin: Int = 40
|
var desiredHourlyMaxInsulin: Int = 40
|
||||||
var desiredDailyMaxInsulin: Int = 180
|
var desiredDailyMaxInsulin: Int = 180
|
||||||
|
var desiredPumpWarning = true
|
||||||
|
var desiredPumpWarningExpiryThresholdHours = 72L
|
||||||
|
|
||||||
fun pumpType(): PumpType = pumpType(deviceType)
|
fun pumpType(): PumpType = pumpType(deviceType)
|
||||||
|
|
||||||
|
@ -333,6 +335,8 @@ class MedtrumPump @Inject constructor(
|
||||||
desiredAlarmSetting = AlarmSetting.values().firstOrNull { it.code == alarmSettingCode } ?: AlarmSetting.LIGHT_VIBRATE_AND_BEEP
|
desiredAlarmSetting = AlarmSetting.values().firstOrNull { it.code == alarmSettingCode } ?: AlarmSetting.LIGHT_VIBRATE_AND_BEEP
|
||||||
desiredHourlyMaxInsulin = sp.getInt(R.string.key_hourly_max_insulin, 40)
|
desiredHourlyMaxInsulin = sp.getInt(R.string.key_hourly_max_insulin, 40)
|
||||||
desiredDailyMaxInsulin = sp.getInt(R.string.key_daily_max_insulin, 180)
|
desiredDailyMaxInsulin = sp.getInt(R.string.key_daily_max_insulin, 180)
|
||||||
|
desiredPumpWarning = sp.getBoolean(R.string.key_pump_warning_notification, true)
|
||||||
|
desiredPumpWarningExpiryThresholdHours = sp.getLong(R.string.key_pump_warning_expiry_hour, 72L)
|
||||||
_pumpSN = pumpSNFromSP
|
_pumpSN = pumpSNFromSP
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,8 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
private const val COMMAND_CONNECTING_TIMEOUT_SEC: Long = 30
|
private const val COMMAND_CONNECTING_TIMEOUT_SEC: Long = 30
|
||||||
private const val ALARM_HOURLY_MAX_CLEAR_CODE = 4
|
private const val ALARM_HOURLY_MAX_CLEAR_CODE = 4
|
||||||
private const val ALARM_DAILY_MAX_CLEAR_CODE = 5
|
private const val ALARM_DAILY_MAX_CLEAR_CODE = 5
|
||||||
|
|
||||||
|
private const val CHECK_EXPIRY_WARNING_TIME_MS = 5 * 60 * 1000L
|
||||||
}
|
}
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
|
@ -135,6 +137,11 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
pumpSync.connectNewPump()
|
pumpSync.connectNewPump()
|
||||||
medtrumPump.setFakeTBRIfNotSet()
|
medtrumPump.setFakeTBRIfNotSet()
|
||||||
}
|
}
|
||||||
|
if (event.isChanged(rh.gs(R.string.key_pump_warning_notification))
|
||||||
|
|| event.isChanged(rh.gs(R.string.key_pump_warning_expiry_hour))
|
||||||
|
) {
|
||||||
|
medtrumPump.loadUserSettingsFromSP()
|
||||||
|
}
|
||||||
if (event.isChanged(rh.gs(R.string.key_alarm_setting))
|
if (event.isChanged(rh.gs(R.string.key_alarm_setting))
|
||||||
|| event.isChanged(rh.gs(R.string.key_patch_expiration))
|
|| event.isChanged(rh.gs(R.string.key_patch_expiration))
|
||||||
|| event.isChanged(rh.gs(R.string.key_hourly_max_insulin))
|
|| event.isChanged(rh.gs(R.string.key_hourly_max_insulin))
|
||||||
|
@ -169,6 +176,12 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
notifyPumpWarning(pumpWarning)
|
notifyPumpWarning(pumpWarning)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
scope.launch {
|
||||||
|
while (true) {
|
||||||
|
checkExpiryWarning()
|
||||||
|
kotlinx.coroutines.delay(CHECK_EXPIRY_WARNING_TIME_MS)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
@ -700,7 +713,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
private fun notifyPumpWarning(alarmState: AlarmState) {
|
private fun notifyPumpWarning(alarmState: AlarmState) {
|
||||||
// Notification on pump warning
|
// Notification on pump warning
|
||||||
if (sp.getBoolean(R.string.key_pump_warning_notification, true) && alarmState != AlarmState.NONE) {
|
if (medtrumPump.desiredPumpWarning && alarmState != AlarmState.NONE) {
|
||||||
uiInteraction.addNotification(
|
uiInteraction.addNotification(
|
||||||
Notification.PUMP_WARNING,
|
Notification.PUMP_WARNING,
|
||||||
rh.gs(R.string.pump_warning, medtrumPump.alarmStateToString(alarmState)),
|
rh.gs(R.string.pump_warning, medtrumPump.alarmStateToString(alarmState)),
|
||||||
|
@ -715,6 +728,25 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkExpiryWarning() {
|
||||||
|
if (medtrumPump.desiredPatchExpiration && medtrumPump.desiredPumpWarning) {
|
||||||
|
val warningAt = medtrumPump.patchStartTime + T.hours(medtrumPump.desiredPumpWarningExpiryThresholdHours).msecs()
|
||||||
|
if (dateUtil.now() >= warningAt && dateUtil.now() <= warningAt + CHECK_EXPIRY_WARNING_TIME_MS) {
|
||||||
|
uiInteraction.addNotification(
|
||||||
|
Notification.PUMP_WARNING,
|
||||||
|
rh.gs(R.string.alarm_pump_expires_soon),
|
||||||
|
Notification.ANNOUNCEMENT,
|
||||||
|
)
|
||||||
|
pumpSync.insertAnnouncement(
|
||||||
|
rh.gs(R.string.alarm_pump_expires_soon),
|
||||||
|
null,
|
||||||
|
medtrumPump.pumpType(),
|
||||||
|
medtrumPump.pumpSN.toString(radix = 16)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** BLECommCallbacks */
|
/** BLECommCallbacks */
|
||||||
override fun onBLEConnected() {
|
override fun onBLEConnected() {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "<<<<< onBLEConnected")
|
aapsLogger.debug(LTag.PUMPCOMM, "<<<<< onBLEConnected")
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<string name="key_alarm_setting" translatable="false">alarm_setting</string>
|
<string name="key_alarm_setting" translatable="false">alarm_setting</string>
|
||||||
<string name="key_patch_expiration" translatable="false">patch_expiration</string>
|
<string name="key_patch_expiration" translatable="false">patch_expiration</string>
|
||||||
<string name="key_pump_warning_notification" translatable="false">pump_warning_notification</string>
|
<string name="key_pump_warning_notification" translatable="false">pump_warning_notification</string>
|
||||||
|
<string name="key_pump_warning_expiry_hour" translatable="false">pump_expiry_warning_hour</string>
|
||||||
<string name="key_hourly_max_insulin" translatable="false">hourly_max_insulin</string>
|
<string name="key_hourly_max_insulin" translatable="false">hourly_max_insulin</string>
|
||||||
<string name="key_daily_max_insulin" translatable="false">daily_max_insulin</string>
|
<string name="key_daily_max_insulin" translatable="false">daily_max_insulin</string>
|
||||||
|
|
||||||
|
@ -145,11 +146,13 @@
|
||||||
<string name="alarm_setting_summary">Select your preferred pump alarm settings.</string>
|
<string name="alarm_setting_summary">Select your preferred pump alarm settings.</string>
|
||||||
<string name="pump_warning_notification_title">Notification on pump warning</string>
|
<string name="pump_warning_notification_title">Notification on pump warning</string>
|
||||||
<string name="pump_warning_notification_summary">Show notification on non critical pump warnings: low battery, low reservoir (20 units) and expires soon. Recommended to leave enabled when pump alarms are set to silent.</string>
|
<string name="pump_warning_notification_summary">Show notification on non critical pump warnings: low battery, low reservoir (20 units) and expires soon. Recommended to leave enabled when pump alarms are set to silent.</string>
|
||||||
|
<string name="pump_warning_expiry_hour_title">Pump expiry warning [hours]</string>
|
||||||
|
<string name="pump_warning_expiry_hour_summary">Show notification on specified hour after activation.</string>
|
||||||
<string name="patch_expiration_title">Patch Expiration</string>
|
<string name="patch_expiration_title">Patch Expiration</string>
|
||||||
<string name="patch_expiration_summary">When enabled, the patch will expire after 3 days, with a grace period of 8 hours after that.</string>
|
<string name="patch_expiration_summary">When enabled, the patch will expire after 3 days, with a grace period of 8 hours after that.</string>
|
||||||
<string name="hourly_max_insulin_title">Hourly Maximum Insulin</string>
|
<string name="hourly_max_insulin_title">Hourly Maximum Insulin [Units]</string>
|
||||||
<string name="hourly_max_insulin_summary">Specify the maximum units of insulin allowed per hour. If exceeded, the pump will suspend.</string>
|
<string name="hourly_max_insulin_summary">Specify the maximum units of insulin allowed per hour. If exceeded, the pump will suspend.</string>
|
||||||
<string name="daily_max_insulin_title">Daily Maximum Insulin</string>
|
<string name="daily_max_insulin_title">Daily Maximum Insulin [Units]</string>
|
||||||
<string name="daily_max_insulin_summary">Specify the maximum units of insulin allowed per day. If exceeded, the pump will suspend.</string>
|
<string name="daily_max_insulin_summary">Specify the maximum units of insulin allowed per day. If exceeded, the pump will suspend.</string>
|
||||||
|
|
||||||
<!-- treatment state-->
|
<!-- treatment state-->
|
||||||
|
|
|
@ -13,12 +13,6 @@
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:title="@string/sn_input_title" />
|
android:title="@string/sn_input_title" />
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="@string/key_patch_expiration"
|
|
||||||
android:title="@string/patch_expiration_title"
|
|
||||||
android:summary="@string/patch_expiration_summary" />
|
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:defaultValue="6"
|
android:defaultValue="6"
|
||||||
android:key="@string/key_alarm_setting"
|
android:key="@string/key_alarm_setting"
|
||||||
|
@ -33,6 +27,22 @@
|
||||||
android:title="@string/pump_warning_notification_title"
|
android:title="@string/pump_warning_notification_title"
|
||||||
android:summary="@string/pump_warning_notification_summary" />
|
android:summary="@string/pump_warning_notification_summary" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:key="@string/key_patch_expiration"
|
||||||
|
android:title="@string/patch_expiration_title"
|
||||||
|
android:summary="@string/patch_expiration_summary" />
|
||||||
|
|
||||||
|
<app.aaps.core.validators.ValidatingEditTextPreference
|
||||||
|
android:defaultValue="72"
|
||||||
|
android:inputType="number"
|
||||||
|
android:key="@string/key_pump_warning_expiry_hour"
|
||||||
|
android:title="@string/pump_warning_expiry_hour_title"
|
||||||
|
android:dialogMessage="@string/pump_warning_expiry_hour_summary"
|
||||||
|
validate:maxNumber="80"
|
||||||
|
validate:minNumber="48"
|
||||||
|
validate:testType="numericRange" />
|
||||||
|
|
||||||
<app.aaps.core.validators.ValidatingEditTextPreference
|
<app.aaps.core.validators.ValidatingEditTextPreference
|
||||||
android:defaultValue="25"
|
android:defaultValue="25"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
|
|
Loading…
Reference in a new issue