Merge pull request #2653 from dv1/combov2-fixes-001

combov2: Additional checks for edge cases
This commit is contained in:
Milos Kozak 2023-08-14 08:42:49 +02:00 committed by GitHub
commit 8f9138c17b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 2 deletions

View file

@ -137,6 +137,7 @@ open class Notification {
const val PATCH_NOT_ACTIVE = 83 const val PATCH_NOT_ACTIVE = 83
const val PUMP_SETTINGS_FAILED = 84 const val PUMP_SETTINGS_FAILED = 84
const val PUMP_TIMEZONE_UPDATE_FAILED = 85 const val PUMP_TIMEZONE_UPDATE_FAILED = 85
const val BLUETOOTH_NOT_SUPPORTED = 86
const val USER_MESSAGE = 1000 const val USER_MESSAGE = 1000

View file

@ -12,6 +12,7 @@ import dagger.android.HasAndroidInjector
import info.nightscout.comboctl.android.AndroidBluetoothInterface import info.nightscout.comboctl.android.AndroidBluetoothInterface
import info.nightscout.comboctl.base.BasicProgressStage import info.nightscout.comboctl.base.BasicProgressStage
import info.nightscout.comboctl.base.BluetoothException import info.nightscout.comboctl.base.BluetoothException
import info.nightscout.comboctl.base.BluetoothNotAvailableException
import info.nightscout.comboctl.base.BluetoothNotEnabledException import info.nightscout.comboctl.base.BluetoothNotEnabledException
import info.nightscout.comboctl.base.ComboException import info.nightscout.comboctl.base.ComboException
import info.nightscout.comboctl.base.DisplayFrame import info.nightscout.comboctl.base.DisplayFrame
@ -346,10 +347,24 @@ class ComboV2Plugin @Inject constructor (
_pairedStateUIFlow.value = paired _pairedStateUIFlow.value = paired
pumpManager = newPumpManager pumpManager = newPumpManager
} catch (_: BluetoothNotAvailableException) {
uiInteraction.addNotification(
Notification.BLUETOOTH_NOT_SUPPORTED,
text = rh.gs(R.string.combov2_bluetooth_not_supported),
level = Notification.URGENT
)
// Deliberately _not_ setting the driver state here before
// exiting this scope. We are essentially aborting the start
// since Bluetooth is not supported by the hardware, so the
// driver cannot do anything, and therefore cannot leave the
// DriverState.NotInitialized state.
aapsLogger.error(LTag.PUMP, "combov2 driver start cannot be completed since the hardware does not support Bluetooth")
return@runWithPermissionCheck
} catch (_: BluetoothNotEnabledException) { } catch (_: BluetoothNotEnabledException) {
uiInteraction.addNotification( uiInteraction.addNotification(
Notification.BLUETOOTH_NOT_ENABLED, Notification.BLUETOOTH_NOT_ENABLED,
text = rh.gs(info.nightscout.core.ui.R.string.ble_not_enabled), text = rh.gs(R.string.combov2_bluetooth_disabled),
level = Notification.INFO level = Notification.INFO
) )
@ -761,7 +776,7 @@ class ComboV2Plugin @Inject constructor (
} catch (_: BluetoothNotEnabledException) { } catch (_: BluetoothNotEnabledException) {
uiInteraction.addNotification( uiInteraction.addNotification(
Notification.BLUETOOTH_NOT_ENABLED, Notification.BLUETOOTH_NOT_ENABLED,
text = rh.gs(info.nightscout.core.ui.R.string.ble_not_enabled), text = rh.gs(R.string.combov2_bluetooth_disabled),
level = Notification.INFO level = Notification.INFO
) )
} catch (e: Exception) { } catch (e: Exception) {

View file

@ -17,9 +17,11 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import info.nightscout.comboctl.base.BasicProgressStage import info.nightscout.comboctl.base.BasicProgressStage
import info.nightscout.comboctl.base.PAIRING_PIN_SIZE
import info.nightscout.comboctl.base.PairingPIN import info.nightscout.comboctl.base.PairingPIN
import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity
import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.core.ui.toast.ToastUtils
import info.nightscout.pump.combov2.ComboV2Plugin import info.nightscout.pump.combov2.ComboV2Plugin
import info.nightscout.pump.combov2.R import info.nightscout.pump.combov2.R
import info.nightscout.pump.combov2.databinding.Combov2PairingActivityBinding import info.nightscout.pump.combov2.databinding.Combov2PairingActivityBinding
@ -334,6 +336,10 @@ class ComboV2PairingActivity : TranslatedDaggerAppCompatActivity() {
// We need to skip whitespaces since the // We need to skip whitespaces since the
// TextWatcher above inserts some. // TextWatcher above inserts some.
val pinString = binding.combov2PinEntryEdit.text.replace(whitespaceRemovalRegex, "") val pinString = binding.combov2PinEntryEdit.text.replace(whitespaceRemovalRegex, "")
if (pinString.length != PAIRING_PIN_SIZE) {
ToastUtils.showToastInUiThread(this, rh.gs(R.string.combov2_pairing_invalid_pin_length, PAIRING_PIN_SIZE, pinString.length))
return@setOnClickListener
}
runBlocking { runBlocking {
val PIN = PairingPIN(pinString.map { it - '0' }.toIntArray()) val PIN = PairingPIN(pinString.map { it - '0' }.toIntArray())
combov2Plugin.providePairingPIN(PIN) combov2Plugin.providePairingPIN(PIN)

View file

@ -53,6 +53,7 @@ buttons at the same time to cancel pairing)\n
<string name="combov2_pairing_combo_scan_timeout_reached">Combo scan timeout reached</string> <string name="combov2_pairing_combo_scan_timeout_reached">Combo scan timeout reached</string>
<string name="combov2_pairing_failed_due_to_error">Pairing failed due to error: %1$s</string> <string name="combov2_pairing_failed_due_to_error">Pairing failed due to error: %1$s</string>
<string name="combov2_pairing_aborted_unknown_reasons">Pairing aborted for unknown reasons</string> <string name="combov2_pairing_aborted_unknown_reasons">Pairing aborted for unknown reasons</string>
<string name="combov2_pairing_invalid_pin_length">"Invalid pairing PIN length: need %1$d digits, got %2$d"</string>
<string name="combov2_scanning_for_pump">Scanning for pump</string> <string name="combov2_scanning_for_pump">Scanning for pump</string>
<string name="combov2_establishing_bt_connection">Establishing Bluetooth connection (attempt no. %1$d)</string> <string name="combov2_establishing_bt_connection">Establishing Bluetooth connection (attempt no. %1$d)</string>
<string name="combov2_pairing_performing_handshake">Performing handshake with pump</string> <string name="combov2_pairing_performing_handshake">Performing handshake with pump</string>
@ -139,4 +140,6 @@ buttons at the same time to cancel pairing)\n
<string name="combov2_refresh_pump_status_after_error">Refreshing pump status after the pump reported an error</string> <string name="combov2_refresh_pump_status_after_error">Refreshing pump status after the pump reported an error</string>
<string name="combov2_go_back">Go back</string> <string name="combov2_go_back">Go back</string>
<string name="combov2_cannot_pair_driver_not_initialized_explanation">Cannot perform pairing because the driver is not initialized. This typically happens because the necessary Bluetooth permissions have not been granted. Go back, grant the Bluetooth permissions, then try again to pair.</string> <string name="combov2_cannot_pair_driver_not_initialized_explanation">Cannot perform pairing because the driver is not initialized. This typically happens because the necessary Bluetooth permissions have not been granted. Go back, grant the Bluetooth permissions, then try again to pair.</string>
<string name="combov2_bluetooth_disabled">Cannot start driver - Bluetooth is disabled</string>
<string name="combov2_bluetooth_not_supported">Driver cannot run - this device does not support Bluetooth</string>
</resources> </resources>