diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java index 6de5376b89..1982a0e7be 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java @@ -103,8 +103,10 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump .toObservable(EventPreferenceChange.class) .observeOn(Schedulers.io()) .subscribe(event -> { - if (event.isChanged(getResourceHelper(), R.string.key_danar_bt_name)) + if (event.isChanged(getResourceHelper(), R.string.key_danar_bt_name)) { danaRPump.setLastConnection(0); + danaRPump.setLastSettingsRead(0); + getCommandQueue().readStatus("DeviceChanged", null); } }) ); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt index e9e001ced0..7f9eb34c7f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRFragment.kt @@ -171,7 +171,7 @@ class DanaRFragment : DaggerFragment() { // GUI functions @Synchronized - internal fun updateGUI() { + fun updateGUI() { if (danar_dailyunits == null) return val pump = danaRPump val plugin: PumpInterface = activePlugin.activePump diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index 759b473d75..7dcc0c29ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -166,9 +166,9 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR disposable.add(rxBus .toObservable(EventDanaRSDeviceChange.class) .observeOn(Schedulers.io()) - .subscribe(event -> loadAddress(), fabricPrivacy::logException) + .subscribe(event -> changePump(), fabricPrivacy::logException) ); - loadAddress(); // load device name + changePump(); // load device name super.onStart(); } @@ -194,10 +194,12 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR } }; - private void loadAddress() { + public void changePump() { mDeviceAddress = sp.getString(R.string.key_danars_address, ""); mDeviceName = sp.getString(R.string.key_danars_name, ""); danaRPump.setLastConnection(0); + danaRPump.setLastSettingsRead(0); + getCommandQueue().readStatus("DeviceChanged", null); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt index 1e6a5f1642..2f537e7d87 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.kt @@ -96,6 +96,9 @@ class BLEComm @Inject internal constructor( return false } + isConnected = false + v3Encryption = false + encryptedDataRead = false isConnecting = true val device = bluetoothAdapter?.getRemoteDevice(address) if (device == null) { @@ -118,13 +121,14 @@ class BLEComm @Inject internal constructor( fun disconnect(from: String) { aapsLogger.debug(LTag.PUMPBTCOMM, "disconnect from: $from") - if (!encryptedDataRead) { + if (!encryptedDataRead && v3Encryption) { // there was no response from pump after started encryption // assume pairing keys are invalid sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName) sp.remove(resourceHelper.gs(R.string.key_danars_v3_pairingkey) + danaRSPlugin.mDeviceName) sp.remove(resourceHelper.gs(R.string.key_danars_v3_randomsynckey) + danaRSPlugin.mDeviceName) ToastUtils.showToastInUiThread(context, R.string.invalidpairing) + danaRSPlugin.changePump() } // cancel previous scheduled disconnection to prevent closing upcoming connection scheduledDisconnection?.cancel(false) diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt index fd93f772aa..20a11124d4 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt @@ -374,12 +374,14 @@ class CommandQueue @Inject constructor( callback?.result(PumpEnactResult(injector).success(true).enacted(false))?.run() return false } + /* this is breaking setting of profile at all if not engineering mode if (!buildHelper.isEngineeringModeOrRelease()) { val notification = Notification(Notification.NOT_ENG_MODE_OR_RELEASE, resourceHelper.gs(R.string.not_eng_mode_or_release), Notification.URGENT) rxBus.send(EventNewNotification(notification)) callback?.result(PumpEnactResult(injector).success(false).enacted(false).comment(resourceHelper.gs(R.string.not_eng_mode_or_release)))?.run() return false } + */ // Compare with pump limits val basalValues = profile.basalValues for (basalValue in basalValues) {