From 9e51f35c410a080506cfbdc5723614276eb6c151 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Thu, 17 Dec 2020 23:02:44 +0100 Subject: [PATCH] Refactor RFSpy.getFirmWareVersion() for testability --- .../pump/common/hw/rileylink/ble/RFSpy.java | 21 +++++++------------ .../ble/defs/RileyLinkFirmwareVersion.java | 7 +++---- .../service/RileyLinkServiceData.java | 2 -- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java index 1aaa9e5008..440a7732be 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java @@ -98,9 +98,9 @@ public class RFSpy { // firmware version public void initializeRileyLink() { bleVersion = getVersion(); - rileyLinkServiceData.firmwareVersion = getFirmwareVersion(); - rileyLinkServiceData.versionCC110 = getCC1110Version(); - + String cc1110Version = getCC1110Version(); + rileyLinkServiceData.versionCC110 = cc1110Version; + rileyLinkServiceData.firmwareVersion = getFirmwareVersion(aapsLogger, bleVersion, cc1110Version); } @@ -125,12 +125,6 @@ public class RFSpy { } } - public boolean isRileyLinkStillAvailable() { - RileyLinkFirmwareVersion firmwareVersion = getFirmwareVersion(); - - return (firmwareVersion != RileyLinkFirmwareVersion.UnknownVersion); - } - private String getCC1110Version() { aapsLogger.debug(LTag.PUMPBTCOMM, "Firmware Version. Get Version - Start"); @@ -159,11 +153,10 @@ public class RFSpy { return null; } - private RileyLinkFirmwareVersion getFirmwareVersion() { - String versionString = getCC1110Version(); - if (versionString != null) { - RileyLinkFirmwareVersion version = RileyLinkFirmwareVersion.getByVersionString(versionString); - aapsLogger.debug(LTag.PUMPBTCOMM, "Firmware Version string: {}, resolved to {}.", versionString, version); + static RileyLinkFirmwareVersion getFirmwareVersion(AAPSLogger aapsLogger, String bleVersion, String cc1110Version) { + if (cc1110Version != null) { + RileyLinkFirmwareVersion version = RileyLinkFirmwareVersion.getByVersionString(cc1110Version); + aapsLogger.debug(LTag.PUMPBTCOMM, "Firmware Version string: {}, resolved to {}.", cc1110Version, version); if (version != RileyLinkFirmwareVersion.UnknownVersion) { return version; diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/defs/RileyLinkFirmwareVersion.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/defs/RileyLinkFirmwareVersion.java index 47e61e9bf6..8a42a64fcb 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/defs/RileyLinkFirmwareVersion.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/defs/RileyLinkFirmwareVersion.java @@ -18,12 +18,11 @@ public enum RileyLinkFirmwareVersion { UnknownVersion(null, null, "???"), // Version1(Version_0_0, Version_0_9, Version_1_0), // Version2(Version_2_0, Version_2_2, Version_2_x), // - Version2AndHigher(Version2, Version_3_x, Version_4_x), // - ; + Version2AndHigher(Version2, Version_3_x, Version_4_x); private static final String FIRMWARE_IDENTIFICATION_PREFIX = "subg_rfspy "; private static final Pattern _version_pattern = Pattern.compile(FIRMWARE_IDENTIFICATION_PREFIX - + "([0-9]+)\\.([0-9]+)"); + + "([0-9]+)\\.([0-9]+)"); static Map mapByVersion; static { @@ -77,7 +76,7 @@ public enum RileyLinkFirmwareVersion { return mapByVersion.get(versionKey); } else { return defaultToLowestMajorVersion(major); // just in case there is new release that we don't cover - // example: 2.3 etc + // example: 2.3 etc } } } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java index f1050b4656..6223d7b182 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java @@ -78,7 +78,6 @@ public class RileyLinkServiceData { private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState, RileyLinkError errorCode, boolean set) { if (set) { - rileyLinkServiceState = newState; lastServiceStateChange = System.currentTimeMillis(); this.rileyLinkError = errorCode; @@ -88,7 +87,6 @@ public class RileyLinkServiceData { rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(rileyLinkServiceState, errorCode, targetDevice)); rxBus.send(new EventRileyLinkDeviceStatusChange(targetDevice, newState, errorCode)); return null; - } else { return rileyLinkServiceState; }