Refactor RFSpy.getFirmWareVersion() for testability
This commit is contained in:
parent
6e30088d1a
commit
9e51f35c41
3 changed files with 10 additions and 20 deletions
|
@ -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;
|
||||
|
|
|
@ -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<String, RileyLinkFirmwareVersion> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue