Skip to content

Commit

Permalink
LnSensorManager deprecation of one sensor numbering format (#7377)
Browse files Browse the repository at this point in the history
Deprecate LocoNetSensorManager's partial support for createSensorName("3:15","L") where "3:15" is supposed to mean "board 3, bit 15", and which returns the equivalent sensor system name of "LS47".  

Logs a one-time (per JMRI session) warning to the System Console log stating that the format is deprecated and support will be removed at a future date.
  • Loading branch information
devel-bobm committed Sep 2, 2019
1 parent 520b1a9 commit 45673df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 10 additions & 0 deletions java/src/jmri/jmrix/loconet/LnSensorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Locale;
import jmri.JmriException;
import jmri.Sensor;
import jmri.util.Log4JUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -135,6 +136,12 @@ public boolean allowMultipleAdditions(String systemName) {
@Override
public String createSystemName(String curAddress, String prefix) throws JmriException {
if (curAddress.contains(":")) {

// NOTE: This format is deprecated in JMRI 4.17.4 on account the
// "byte:bit" format cannot be used under normal JMRI usage
// circumstances. It is retained for the normal deprecation period
// in order to support any atypical usage patterns.

int board = 0;
int channel = 0;
// Address format passed is in the form of board:channel or T:turnout address
Expand All @@ -161,6 +168,9 @@ public String createSystemName(String curAddress, String prefix) throws JmriExce
} else {
iName = 16 * board + channel - 16;
}
jmri.util.Log4JUtil.warnOnce(log,
"LnSensorManager.createSystemName(curAddress, prefix) support for curAddress using the '{}' format is deprecated as of JMRI 4.17.4 and will be removed in a future JMRI release. Use the curAddress format '{}' instead.",
curAddress, iName);
} else {
// Entered in using the old format
try {
Expand Down
17 changes: 16 additions & 1 deletion java/test/jmri/jmrix/loconet/LnSensorManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ public void testAsAbstractFactory() {

}

@Test
public void testDeprecationWarningSensorNumberFormat() {
boolean excep= false;
String s = "";
try {
s = l.createSystemName("3:5", "L");
} catch (jmri.JmriException e) {
excep = true;
}
Assert.assertEquals("no exception during createSystemName for arguments '3:5', 'L'", false, excep);
Assert.assertEquals("check createSystemName for arguments '3:5', 'L'", "LS37", s);
jmri.util.JUnitAppender.assertWarnMessage(
"LnSensorManager.createSystemName(curAddress, prefix) support for curAddress using the '3:5' format is deprecated as of JMRI 4.17.4 and will be removed in a future JMRI release. Use the curAddress format '37' instead.");
}

// The minimal setup for log4J
@Override
@Before
Expand All @@ -115,5 +130,5 @@ public void tearDown() {
}

private final static Logger log = LoggerFactory.getLogger(LnSensorManagerTest.class);

}

0 comments on commit 45673df

Please sign in to comment.