[insteon] Fix SAT warnings (#10688)

Signed-off-by: Rob Nielsen <rob.nielsen@yahoo.com>
This commit is contained in:
robnielsen 2021-05-14 03:22:55 -05:00 committed by GitHub
parent 801100cee1
commit 9ba28a50cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 44 deletions

View File

@ -218,7 +218,7 @@ public class InsteonCommandExtension extends AbstractConsoleCommandExtension imp
} }
private void startMonitoring(Console console, String addr) { private void startMonitoring(Console console, String addr) {
if (addr.equalsIgnoreCase("all")) { if ("all".equalsIgnoreCase(addr)) {
if (!monitorAllDevices) { if (!monitorAllDevices) {
monitorAllDevices = true; monitorAllDevices = true;
monitoredAddresses.clear(); monitoredAddresses.clear();
@ -255,7 +255,7 @@ public class InsteonCommandExtension extends AbstractConsoleCommandExtension imp
return; return;
} }
if (addr.equalsIgnoreCase("all")) { if ("all".equalsIgnoreCase(addr)) {
if (monitorAllDevices) { if (monitorAllDevices) {
monitorAllDevices = false; monitorAllDevices = false;
console.println("Stopped monitoring all devices."); console.println("Stopped monitoring all devices.");

View File

@ -18,7 +18,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@ -119,7 +118,7 @@ public class DeviceTypeLoader {
*/ */
private void processDevice(Element e) throws SAXException { private void processDevice(Element e) throws SAXException {
String productKey = e.getAttribute("productKey"); String productKey = e.getAttribute("productKey");
if (productKey.equals("")) { if ("".equals(productKey)) {
throw new SAXException("device in device_types file has no product key!"); throw new SAXException("device in device_types file has no product key!");
} }
if (deviceTypes.containsKey(productKey)) { if (deviceTypes.containsKey(productKey)) {
@ -135,13 +134,14 @@ public class DeviceTypeLoader {
continue; continue;
} }
Element subElement = (Element) node; Element subElement = (Element) node;
if (subElement.getNodeName().equals("model")) { String nodeName = subElement.getNodeName();
if ("model".equals(nodeName)) {
devType.setModel(subElement.getTextContent()); devType.setModel(subElement.getTextContent());
} else if (subElement.getNodeName().equals("description")) { } else if ("description".equals(nodeName)) {
devType.setDescription(subElement.getTextContent()); devType.setDescription(subElement.getTextContent());
} else if (subElement.getNodeName().equals("feature")) { } else if ("feature".equals(nodeName)) {
processFeature(devType, subElement); processFeature(devType, subElement);
} else if (subElement.getNodeName().equals("feature_group")) { } else if ("feature_group".equals(nodeName)) {
processFeatureGroup(devType, subElement); processFeatureGroup(devType, subElement);
} }
deviceTypes.put(productKey, devType); deviceTypes.put(productKey, devType);
@ -150,7 +150,7 @@ public class DeviceTypeLoader {
private String processFeature(DeviceType devType, Element e) throws SAXException { private String processFeature(DeviceType devType, Element e) throws SAXException {
String name = e.getAttribute("name"); String name = e.getAttribute("name");
if (name.equals("")) { if ("".equals(name)) {
throw new SAXException("feature " + e.getNodeName() + " has feature without name!"); throw new SAXException("feature " + e.getNodeName() + " has feature without name!");
} }
if (!name.equals(name.toLowerCase())) { if (!name.equals(name.toLowerCase())) {
@ -164,11 +164,11 @@ public class DeviceTypeLoader {
private String processFeatureGroup(DeviceType devType, Element e) throws SAXException { private String processFeatureGroup(DeviceType devType, Element e) throws SAXException {
String name = e.getAttribute("name"); String name = e.getAttribute("name");
if (name.equals("")) { if ("".equals(name)) {
throw new SAXException("feature group " + e.getNodeName() + " has no name attr!"); throw new SAXException("feature group " + e.getNodeName() + " has no name attr!");
} }
String type = e.getAttribute("type"); String type = e.getAttribute("type");
if (type.equals("")) { if ("".equals(type)) {
throw new SAXException("feature group " + e.getNodeName() + " has no type attr!"); throw new SAXException("feature group " + e.getNodeName() + " has no type attr!");
} }
FeatureGroup fg = new FeatureGroup(name, type); FeatureGroup fg = new FeatureGroup(name, type);
@ -179,9 +179,10 @@ public class DeviceTypeLoader {
continue; continue;
} }
Element subElement = (Element) node; Element subElement = (Element) node;
if (subElement.getNodeName().equals("feature")) { String nodeName = subElement.getNodeName();
if ("feature".equals(nodeName)) {
fg.addFeature(processFeature(devType, subElement)); fg.addFeature(processFeature(devType, subElement));
} else if (subElement.getNodeName().equals("feature_group")) { } else if ("feature_group".equals(nodeName)) {
fg.addFeature(processFeatureGroup(devType, subElement)); fg.addFeature(processFeatureGroup(devType, subElement));
} }
} }
@ -191,16 +192,6 @@ public class DeviceTypeLoader {
return (name); return (name);
} }
/**
* Helper function for debugging
*/
private void logDeviceTypes() {
for (Entry<String, DeviceType> dt : getDeviceTypes().entrySet()) {
String msg = String.format("%-10s->", dt.getKey()) + dt.getValue();
logger.debug("{}", msg);
}
}
/** /**
* Singleton instance function, creates DeviceTypeLoader * Singleton instance function, creates DeviceTypeLoader
* *

View File

@ -70,7 +70,7 @@ public class FeatureTemplateLoader {
Node node = nodes.item(i); Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getNodeType() == Node.ELEMENT_NODE) {
Element e = (Element) node; Element e = (Element) node;
if (e.getTagName().equals("feature")) { if ("feature".equals(e.getTagName())) {
features.add(parseFeature(e)); features.add(parseFeature(e));
} }
} }
@ -126,7 +126,7 @@ public class FeatureTemplateLoader {
private static void parseMessageHandler(Element e, FeatureTemplate f) throws DOMException, ParsingException { private static void parseMessageHandler(Element e, FeatureTemplate f) throws DOMException, ParsingException {
HandlerEntry he = makeHandlerEntry(e); HandlerEntry he = makeHandlerEntry(e);
if (e.getAttribute("default").equals("true")) { if ("true".equals(e.getAttribute("default"))) {
f.setDefaultMessageHandler(he); f.setDefaultMessageHandler(he);
} else { } else {
String attr = e.getAttribute("cmd"); String attr = e.getAttribute("cmd");
@ -137,7 +137,7 @@ public class FeatureTemplateLoader {
private static void parseCommandHandler(Element e, FeatureTemplate f) throws ParsingException { private static void parseCommandHandler(Element e, FeatureTemplate f) throws ParsingException {
HandlerEntry he = makeHandlerEntry(e); HandlerEntry he = makeHandlerEntry(e);
if (e.getAttribute("default").equals("true")) { if ("true".equals(e.getAttribute("default"))) {
f.setDefaultCommandHandler(he); f.setDefaultCommandHandler(he);
} else { } else {
Class<? extends Command> command = parseCommandClass(e.getAttribute("command")); Class<? extends Command> command = parseCommandClass(e.getAttribute("command"));
@ -156,13 +156,13 @@ public class FeatureTemplateLoader {
} }
private static Class<? extends Command> parseCommandClass(String c) throws ParsingException { private static Class<? extends Command> parseCommandClass(String c) throws ParsingException {
if (c.equals("OnOffType")) { if ("OnOffType".equals(c)) {
return OnOffType.class; return OnOffType.class;
} else if (c.equals("PercentType")) { } else if ("PercentType".equals(c)) {
return PercentType.class; return PercentType.class;
} else if (c.equals("DecimalType")) { } else if ("DecimalType".equals(c)) {
return DecimalType.class; return DecimalType.class;
} else if (c.equals("IncreaseDecreaseType")) { } else if ("IncreaseDecreaseType".equals(c)) {
return IncreaseDecreaseType.class; return IncreaseDecreaseType.class;
} else { } else {
throw new ParsingException("Unknown Command Type"); throw new ParsingException("Unknown Command Type");

View File

@ -1078,9 +1078,9 @@ public abstract class MessageHandler {
@Nullable @Nullable
State state; State state;
String scale = getStringParameter("scale", null); String scale = getStringParameter("scale", null);
if (scale != null && scale.equals("celsius")) { if ("celsius".equals(scale)) {
state = new QuantityType<>(dvalue, SIUnits.CELSIUS); state = new QuantityType<>(dvalue, SIUnits.CELSIUS);
} else if (scale != null && scale.equals("fahrenheit")) { } else if ("fahrenheit".equals(scale)) {
state = new QuantityType<>(dvalue, ImperialUnits.FAHRENHEIT); state = new QuantityType<>(dvalue, ImperialUnits.FAHRENHEIT);
} else { } else {
state = new DecimalType(dvalue); state = new DecimalType(dvalue);
@ -1102,7 +1102,7 @@ public abstract class MessageHandler {
return 0; return 0;
} }
int value = 0; int value = 0;
if (lowByte.equals("group")) { if ("group".equals(lowByte)) {
value = group; value = group;
} else { } else {
value = msg.getByte(lowByte) & 0xFF; value = msg.getByte(lowByte) & 0xFF;

View File

@ -58,7 +58,7 @@ public class SerialIOStream extends IOStream {
} else { } else {
String key = paramParts[0]; String key = paramParts[0];
String value = paramParts[1]; String value = paramParts[1];
if (key.equals("baudRate")) { if ("baudRate".equals(key)) {
try { try {
baudRate = Integer.parseInt(value); baudRate = Integer.parseInt(value);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {

View File

@ -52,7 +52,6 @@ public class InsteonNetworkHandler extends BaseBridgeHandler {
private final Logger logger = LoggerFactory.getLogger(InsteonNetworkHandler.class); private final Logger logger = LoggerFactory.getLogger(InsteonNetworkHandler.class);
private @Nullable InsteonNetworkConfiguration config;
private @Nullable InsteonBinding insteonBinding; private @Nullable InsteonBinding insteonBinding;
private @Nullable InsteonDeviceDiscoveryService insteonDeviceDiscoveryService; private @Nullable InsteonDeviceDiscoveryService insteonDeviceDiscoveryService;
private @Nullable ScheduledFuture<?> pollingJob = null; private @Nullable ScheduledFuture<?> pollingJob = null;
@ -77,17 +76,9 @@ public class InsteonNetworkHandler extends BaseBridgeHandler {
@Override @Override
public void initialize() { public void initialize() {
logger.debug("Starting Insteon bridge"); logger.debug("Starting Insteon bridge");
config = getConfigAs(InsteonNetworkConfiguration.class); InsteonNetworkConfiguration config = getConfigAs(InsteonNetworkConfiguration.class);
scheduler.execute(() -> { scheduler.execute(() -> {
InsteonNetworkConfiguration config = this.config;
if (config == null) {
String msg = "Initialization failed, configuration is null.";
logger.warn(msg);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, msg);
return;
}
SerialPortManager serialPortManager = this.serialPortManager; SerialPortManager serialPortManager = this.serialPortManager;
if (serialPortManager == null) { if (serialPortManager == null) {
String msg = "Initialization failed, serial port manager is null."; String msg = "Initialization failed, serial port manager is null.";