-
Notifications
You must be signed in to change notification settings - Fork 5.2k
sms bolus from AAPSClient #3507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 21 commits
8013f90
7dd7c3f
793c36e
e6d87d5
9c86d09
d18ab0d
a3107c0
7991263
b093f7f
9f2a45e
e5319cc
80a7ea6
3fff443
36d09dc
a8d5b73
b1f2cd8
ff2907e
4f72df7
8fa040b
28da6c7
d747a0f
7992971
7a4239a
b37521a
98d4c68
32e42aa
8fb66e5
1f5aaf3
3260089
0c78c70
f7deff2
e26ffd7
f4df8df
659759c
21bbf38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package app.aaps.core.interfaces.smsCommunicator | ||
|
|
||
| fun formatBolusCarbsCommand(insulin: Double, carbs: Int, time: String? = null, set_alarm: Boolean = false): String { | ||
| var msg = "Boluscarbs " + "%.2f ".format(insulin) + carbs.toString() | ||
| if (!time.isNullOrEmpty()) { | ||
| if(time.all { it.isDigit() }) | ||
| // xx min offset | ||
| msg += " +" + time | ||
| else | ||
| // either of -yy, +xx, 1:23, 2:34PM | ||
| msg += " " + time | ||
|
|
||
| if(set_alarm == true) | ||
| msg += " alarm" | ||
| } | ||
| return msg | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,7 +70,7 @@ enum class BooleanKey( | |
| AutotuneCircadianIcIsf("autotune_circadian_ic_isf", false), | ||
| AutotuneAdditionalLog("autotune_additional_log", false), | ||
|
|
||
| SmsAllowRemoteCommands("smscommunicator_remotecommandsallowed", false), | ||
| SmsAllowRemoteCommands("smscommunicator_remotecommandsallowed", false, showInApsMode = false, showInPumpControlMode = false), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This plugin is intended only for AAPSClient. It sends SMS commands to phone running AAPS. Both AAPS and control app are on the pump controlling phone so presence of that plugin would be confusing. |
||
| SmsReportPumpUnreachable("smscommunicator_report_pump_unreachable", true), | ||
|
|
||
| VirtualPumpStatusUpload("virtualpump_uploadstatus", false, showInNsClientMode = false), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,12 +37,16 @@ import app.aaps.core.interfaces.resources.ResourceHelper | |
| import app.aaps.core.interfaces.rx.bus.RxBus | ||
| import app.aaps.core.interfaces.rx.events.EventRefreshOverview | ||
| import app.aaps.core.interfaces.sharedPreferences.SP | ||
| import app.aaps.core.interfaces.smsCommunicator.Sms | ||
| import app.aaps.core.interfaces.smsCommunicator.SmsCommunicator | ||
| import app.aaps.core.interfaces.smsCommunicator.formatBolusCarbsCommand | ||
| import app.aaps.core.interfaces.ui.UiInteraction | ||
| import app.aaps.core.interfaces.utils.DateUtil | ||
| import app.aaps.core.interfaces.utils.DecimalFormatter | ||
| import app.aaps.core.interfaces.utils.Round | ||
| import app.aaps.core.keys.BooleanKey | ||
| import app.aaps.core.keys.Preferences | ||
| import app.aaps.core.keys.StringKey | ||
| import app.aaps.core.objects.constraints.ConstraintObject | ||
| import app.aaps.core.objects.extensions.formatColor | ||
| import app.aaps.core.objects.extensions.highValueToUnitsToString | ||
|
|
@@ -63,6 +67,7 @@ class BolusWizard @Inject constructor( | |
| val injector: HasAndroidInjector | ||
| ) { | ||
|
|
||
| @Inject lateinit var smsCommunicator: SmsCommunicator | ||
| @Inject lateinit var aapsLogger: AAPSLogger | ||
| @Inject lateinit var rh: ResourceHelper | ||
| @Inject lateinit var rxBus: RxBus | ||
|
|
@@ -86,9 +91,12 @@ class BolusWizard @Inject constructor( | |
| @Inject lateinit var processedDeviceStatusData: ProcessedDeviceStatusData | ||
|
|
||
| var timeStamp: Long | ||
| // var phoneNumber: String | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review https://github.com/nightscout/AndroidAPS/pull/3507/files and cleanup the code |
||
|
|
||
| init { | ||
| injector.androidInjector().inject(this) | ||
| // why this@BolusWizar.phoneNumber not visible in scoped DetailedBolusInfo().apply | ||
| // phoneNumber = preferences.get(StringKey.SmsReceiverNumber) | ||
| timeStamp = dateUtil.now() | ||
| } | ||
|
|
||
|
|
@@ -330,7 +338,7 @@ class BolusWizard @Inject constructor( | |
| } | ||
|
|
||
| private fun confirmMessageAfterConstraints(context: Context, advisor: Boolean, quickWizardEntry: QuickWizardEntry? = null): Spanned { | ||
|
|
||
| val phoneNumber = preferences.get(StringKey.SmsReceiverNumber) | ||
| val actions: LinkedList<String> = LinkedList() | ||
| if (insulinAfterConstraints > 0) { | ||
| val pct = if (percentageCorrection != 100) " ($percentageCorrection%)" else "" | ||
|
|
@@ -370,8 +378,12 @@ class BolusWizard @Inject constructor( | |
| rh.gs(app.aaps.core.ui.R.string.bolus_constraint_applied_warn, calculatedTotalInsulin, insulinAfterConstraints) | ||
| .formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) | ||
| ) | ||
| if (config.AAPSCLIENT && insulinAfterConstraints > 0) | ||
| actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) | ||
| val bolusOrCarbs = (insulinAfterConstraints > 0 || carbs > 0) | ||
| if (config.AAPSCLIENT && bolusOrCarbs) | ||
| if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank() && bolusOrCarbs) | ||
| actions.add(rh.gs(app.aaps.core.ui.R.string.sms_request_notification).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) | ||
| else | ||
| actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) | ||
| if (useAlarm && !advisor && carbs > 0 && carbTime > 0) | ||
| actions.add(rh.gs(app.aaps.core.ui.R.string.alarminxmin, carbTime).formatColor(context, rh, app.aaps.core.ui.R.attr.infoColor)) | ||
| if (advisor) | ||
|
|
@@ -421,6 +433,14 @@ class BolusWizard @Inject constructor( | |
| } | ||
|
|
||
| private fun bolusAdvisorProcessing(ctx: Context) { | ||
| val phoneNumber = preferences.get(StringKey.SmsReceiverNumber) | ||
| if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) { | ||
| // Bolus advisor is not supported because automation.scheduleAutomationEventEatReminder() can't be set on AAPSClient phone. | ||
| // In order to do so AAPSClient phone would need to wait in pooling for bolus confirmation message. I don't want to block app on that. | ||
| OKDialog.show(ctx, rh.gs(app.aaps.core.ui.R.string.boluswizard), rh.gs(app.aaps.core.ui.R.string.bolus_advisor_not_supported)) | ||
| return | ||
| } | ||
|
|
||
| val confirmMessage = confirmMessageAfterConstraints(ctx, advisor = true) | ||
| OKDialog.showConfirmation(ctx, rh.gs(app.aaps.core.ui.R.string.boluswizard), confirmMessage, { | ||
| DetailedBolusInfo().apply { | ||
|
|
@@ -538,15 +558,21 @@ class BolusWizard @Inject constructor( | |
| ValueWithUnit.Minute(carbTime).takeIf { carbTime != 0 } | ||
| ).filterNotNull() | ||
| ) | ||
| commandQueue.bolus(this, object : Callback() { | ||
| override fun run() { | ||
| if (!result.success) { | ||
| uiInteraction.runAlarm(result.comment, rh.gs(app.aaps.core.ui.R.string.treatmentdeliveryerror), app.aaps.core.ui.R.raw.boluserror) | ||
| } else if (useAlarm && carbs > 0 && carbTime > 0) { | ||
| automation.scheduleTimeToEatReminder(T.mins(carbTime.toLong()).secs().toInt()) | ||
| val phoneNumber = preferences.get(StringKey.SmsReceiverNumber) | ||
| if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) { | ||
|
jgr-lab marked this conversation as resolved.
Outdated
|
||
| rh.gs(app.aaps.core.ui.R.string.sms_request_notification).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) | ||
| smsCommunicator.sendSMS(Sms(phoneNumber, formatBolusCarbsCommand(insulin, this@BolusWizard.carbs, this@BolusWizard.carbTime.toString(), useAlarm))) | ||
| } else { | ||
| commandQueue.bolus(this, object : Callback() { | ||
| override fun run() { | ||
| if (!result.success) { | ||
| uiInteraction.runAlarm(result.comment, rh.gs(app.aaps.core.ui.R.string.treatmentdeliveryerror), app.aaps.core.ui.R.raw.boluserror) | ||
| } else if (config.APS && useAlarm && carbs > 0 && carbTime > 0) { | ||
| automation.scheduleTimeToEatReminder(T.mins(carbTime.toLong()).secs().toInt()) | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
| } | ||
| bolusCalculatorResult?.let { persistenceLayer.insertOrUpdateBolusCalculatorResult(it).blockingGet() } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -454,13 +454,16 @@ | |
| <!-- BolusWizard --> | ||
| <string name="bolus_advisor">Bolus advisor</string> | ||
| <string name="bolus_advisor_message">You have high glycemia. Instead of eating now it\'s recommended to wait for better glycemia. Do you want to do a correction bolus now and remind you when it\'s time to eat? In this case no carbs will be recorded and you must use wizard again when we remind you.</string> | ||
| <string name="bolus_advisor_not_supported">Bolus advisor doesn\'t work with SMS commands. Wait till BG drops or provide correction bolus using Insulin or Treatment buttons.</string> | ||
|
|
||
| <string name="cobvsiob">COB vs IOB</string> | ||
| <string name="slowabsorptiondetected"><![CDATA[<font color=\'%1$s\'>!!!!! Slow carbs absorption detected: %2$d%% of time. Double check your calculation. COB can be overestimated thus more insulin could be given !!!!!</font>]]></string> | ||
| <string name="partialboluswizard">Deliver this part of bolus wizard result [%]</string> | ||
| <string name="sms_receiver_number">Receiver phone number for sms commands sent from AAPSClient phone</string> | ||
| <string name="partialboluswizard_reset_time">Old glycemia time threshold [min]</string> | ||
| <string name="bolus_constraint_applied_warn">Bolus constraint applied: %1$.2f U to %2$.2f U</string> | ||
| <string name="bolus_recorded_only">Bolus will be recorded only (not delivered by pump)</string> | ||
| <string name="sms_request_notification">SMS command will be send</string> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "SMS command will be send" seem to be bad grammar. "SMS command will be sent" or "The SMS command will be sent" is probably better if I understand the context. :) |
||
| <string name="advisoralarm">Run alarm when is time to eat</string> | ||
| <string name="no_action_selected">No action selected, nothing will happen</string> | ||
| <string name="carb_equal_zero_no_action">Carbs = 0. No action taken!</string> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
15 minutes seems to be too much. In my case I've set some max carbs limit for single meal. It's intended to limit bolus to make sure carbs absorption kicks in on time. When meal is bigger than max carb then I split calculations into 2 meal with 5 minutes delay. 5 should also prevent accidental bolus at the same time from multiple caregivers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree. I have the same process in place with the treatment on my two kids. Set bolus limit for safety, leading to mandatory split bolus for regular meals.