diff --git a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminDeviceClient.kt b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminDeviceClient.kt index 358b7b9f16..8ef347d8a6 100644 --- a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminDeviceClient.kt +++ b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminDeviceClient.kt @@ -89,8 +89,13 @@ class GarminDeviceClient( bindLock.notifyAll() } if (notifyReceiver) receiver.onConnect(this@GarminDeviceClient) - ciq.connectedDevices?.forEach { d -> - receiver.onConnectDevice(this@GarminDeviceClient, d.deviceIdentifier, d.friendlyName) } + try { + ciq.connectedDevices?.forEach { d -> + receiver.onConnectDevice(this@GarminDeviceClient, d.deviceIdentifier, d.friendlyName) + } + } catch (e: Exception) { + aapsLogger.error(LTag.GARMIN, "getting devices failed", e) + } } override fun onServiceDisconnected(name: ComponentName?) { synchronized(bindLock) { diff --git a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminMessenger.kt b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminMessenger.kt index 87c60ece7e..8f8671a6ec 100644 --- a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminMessenger.kt +++ b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminMessenger.kt @@ -26,7 +26,7 @@ class GarminMessenger( appIdNames.putAll(applicationIdNames) if (enableConnectIq) startDeviceClient() if (enableSimulator) { - appIdNames["SimAp"] = "SimulatorApp" + appIdNames["SimApp"] = "SimulatorApp" GarminSimulatorClient(aapsLogger, this) } } diff --git a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminPlugin.kt b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminPlugin.kt index 50f9410e7e..ce67a6e8bb 100644 --- a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminPlugin.kt +++ b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminPlugin.kt @@ -86,12 +86,13 @@ class GarminPlugin @Inject constructor( private val garminAapsKey get() = sp.getString("garmin_aaps_key", "") private fun onPreferenceChange(event: EventPreferenceChange) { - aapsLogger.info(LTag.GARMIN, "preferences change ${event.changedKey}") when (event.changedKey) { "communication_debug_mode" -> setupGarminMessenger() "communication_http", "communication_http_port" -> setupHttpServer() "garmin_aaps_key" -> sendPhoneAppMessage() + else -> return } + aapsLogger.info(LTag.GARMIN, "preferences change ${event.changedKey}") } private fun setupGarminMessenger() { @@ -120,7 +121,7 @@ class GarminPlugin @Inject constructor( .subscribe(::onNewBloodGlucose) ) setupHttpServer() - setupGarminMessenger() + // setupGarminMessenger() } fun setupHttpServer() { @@ -167,8 +168,10 @@ class GarminPlugin @Inject constructor( @VisibleForTesting fun onConnectDevice(device: GarminDevice) { - aapsLogger.info(LTag.GARMIN, "onConnectDevice $device sending glucose") - if (garminAapsKey.isNotEmpty()) sendPhoneAppMessage(device) + if (garminAapsKey.isNotEmpty()) { + aapsLogger.info(LTag.GARMIN, "onConnectDevice $device sending glucose") + sendPhoneAppMessage(device) + } } private fun sendPhoneAppMessage(device: GarminDevice) { diff --git a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminSimulatorClient.kt b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminSimulatorClient.kt index f473773a2a..56b1ce1449 100644 --- a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminSimulatorClient.kt +++ b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/GarminSimulatorClient.kt @@ -83,7 +83,8 @@ class GarminSimulatorClient( } } } catch (e: SocketException) { - aapsLogger.warn(LTag.GARMIN, "socket read failed ${e.message}") + aapsLogger.warn(LTag.GARMIN, "socket read failed ${e.message}") + break } } aapsLogger.info(LTag.GARMIN, "disconnect ${device.name}" ) @@ -162,7 +163,7 @@ class GarminSimulatorClient( override fun isDisposed() = serverSocket.isClosed override fun retrieveApplicationInfo(device: GarminDevice, appId: String, appName: String) { - receiver.onApplicationInfo(device, appId, true) + receiver.onApplicationInfo(device, appId, appId == iqApp.applicationID) } private fun getConnection(device: GarminDevice): Connection? { diff --git a/plugins/sync/src/test/kotlin/app/aaps/plugins/sync/garmin/GarminSimulatorClientTest.kt b/plugins/sync/src/test/kotlin/app/aaps/plugins/sync/garmin/GarminSimulatorClientTest.kt index a4b422616b..b713af0f05 100644 --- a/plugins/sync/src/test/kotlin/app/aaps/plugins/sync/garmin/GarminSimulatorClientTest.kt +++ b/plugins/sync/src/test/kotlin/app/aaps/plugins/sync/garmin/GarminSimulatorClientTest.kt @@ -62,7 +62,7 @@ class GarminSimulatorClientTest: TestBase() { verify(receiver).onConnect(client) verify(receiver, timeout(1_000)).onConnectDevice(eq(client), any(), any()) } - verify(receiver).onReceiveMessage( + verify(receiver, timeout(1_000)).onReceiveMessage( eq(client), eq(device!!.id), eq("SimApp"), argThat { p -> payload.contentEquals(p) }) }