From f8271089e55e80fc8e02804ddfcd85e6fab245c2 Mon Sep 17 00:00:00 2001 From: robnielsen Date: Fri, 14 May 2021 03:22:55 -0500 Subject: [PATCH] [insteon] Fix SAT warnings (#10688) Signed-off-by: Rob Nielsen --- .../command/InsteonCommandExtension.java | 4 +-- .../internal/device/DeviceTypeLoader.java | 33 +++++++------------ .../device/FeatureTemplateLoader.java | 14 ++++---- .../internal/device/MessageHandler.java | 6 ++-- .../internal/driver/SerialIOStream.java | 2 +- .../handler/InsteonNetworkHandler.java | 11 +------ 6 files changed, 26 insertions(+), 44 deletions(-) diff --git a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/command/InsteonCommandExtension.java b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/command/InsteonCommandExtension.java index 10e2a613def5e..71755823bd100 100644 --- a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/command/InsteonCommandExtension.java +++ b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/command/InsteonCommandExtension.java @@ -218,7 +218,7 @@ private void displayMonitoredDevices(Console console) { } private void startMonitoring(Console console, String addr) { - if (addr.equalsIgnoreCase("all")) { + if ("all".equalsIgnoreCase(addr)) { if (!monitorAllDevices) { monitorAllDevices = true; monitoredAddresses.clear(); @@ -255,7 +255,7 @@ private void stopMonitoring(Console console, String addr) { return; } - if (addr.equalsIgnoreCase("all")) { + if ("all".equalsIgnoreCase(addr)) { if (monitorAllDevices) { monitorAllDevices = false; console.println("Stopped monitoring all devices."); diff --git a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/DeviceTypeLoader.java b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/DeviceTypeLoader.java index f4fe134bc2aae..96b8b8f5daab4 100644 --- a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/DeviceTypeLoader.java +++ b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/DeviceTypeLoader.java @@ -18,7 +18,6 @@ import java.io.InputStream; import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -119,7 +118,7 @@ public void loadDeviceTypesXML(String aFileName) throws ParserConfigurationExcep */ private void processDevice(Element e) throws SAXException { String productKey = e.getAttribute("productKey"); - if (productKey.equals("")) { + if ("".equals(productKey)) { throw new SAXException("device in device_types file has no product key!"); } if (deviceTypes.containsKey(productKey)) { @@ -135,13 +134,14 @@ private void processDevice(Element e) throws SAXException { continue; } Element subElement = (Element) node; - if (subElement.getNodeName().equals("model")) { + String nodeName = subElement.getNodeName(); + if ("model".equals(nodeName)) { devType.setModel(subElement.getTextContent()); - } else if (subElement.getNodeName().equals("description")) { + } else if ("description".equals(nodeName)) { devType.setDescription(subElement.getTextContent()); - } else if (subElement.getNodeName().equals("feature")) { + } else if ("feature".equals(nodeName)) { processFeature(devType, subElement); - } else if (subElement.getNodeName().equals("feature_group")) { + } else if ("feature_group".equals(nodeName)) { processFeatureGroup(devType, subElement); } deviceTypes.put(productKey, devType); @@ -150,7 +150,7 @@ private void processDevice(Element e) throws SAXException { private String processFeature(DeviceType devType, Element e) throws SAXException { String name = e.getAttribute("name"); - if (name.equals("")) { + if ("".equals(name)) { throw new SAXException("feature " + e.getNodeName() + " has feature without name!"); } if (!name.equals(name.toLowerCase())) { @@ -164,11 +164,11 @@ private String processFeature(DeviceType devType, Element e) throws SAXException private String processFeatureGroup(DeviceType devType, Element e) throws SAXException { String name = e.getAttribute("name"); - if (name.equals("")) { + if ("".equals(name)) { throw new SAXException("feature group " + e.getNodeName() + " has no name attr!"); } String type = e.getAttribute("type"); - if (type.equals("")) { + if ("".equals(type)) { throw new SAXException("feature group " + e.getNodeName() + " has no type attr!"); } FeatureGroup fg = new FeatureGroup(name, type); @@ -179,9 +179,10 @@ private String processFeatureGroup(DeviceType devType, Element e) throws SAXExce continue; } Element subElement = (Element) node; - if (subElement.getNodeName().equals("feature")) { + String nodeName = subElement.getNodeName(); + if ("feature".equals(nodeName)) { fg.addFeature(processFeature(devType, subElement)); - } else if (subElement.getNodeName().equals("feature_group")) { + } else if ("feature_group".equals(nodeName)) { fg.addFeature(processFeatureGroup(devType, subElement)); } } @@ -191,16 +192,6 @@ private String processFeatureGroup(DeviceType devType, Element e) throws SAXExce return (name); } - /** - * Helper function for debugging - */ - private void logDeviceTypes() { - for (Entry dt : getDeviceTypes().entrySet()) { - String msg = String.format("%-10s->", dt.getKey()) + dt.getValue(); - logger.debug("{}", msg); - } - } - /** * Singleton instance function, creates DeviceTypeLoader * diff --git a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/FeatureTemplateLoader.java b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/FeatureTemplateLoader.java index b297bfdb9d4c2..ff05e9f4e37f1 100644 --- a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/FeatureTemplateLoader.java +++ b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/FeatureTemplateLoader.java @@ -70,7 +70,7 @@ public static List readTemplates(InputStream input) throws IOEx Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) node; - if (e.getTagName().equals("feature")) { + if ("feature".equals(e.getTagName())) { features.add(parseFeature(e)); } } @@ -126,7 +126,7 @@ private static HandlerEntry makeHandlerEntry(Element e) throws ParsingException private static void parseMessageHandler(Element e, FeatureTemplate f) throws DOMException, ParsingException { HandlerEntry he = makeHandlerEntry(e); - if (e.getAttribute("default").equals("true")) { + if ("true".equals(e.getAttribute("default"))) { f.setDefaultMessageHandler(he); } else { String attr = e.getAttribute("cmd"); @@ -137,7 +137,7 @@ private static void parseMessageHandler(Element e, FeatureTemplate f) throws DOM private static void parseCommandHandler(Element e, FeatureTemplate f) throws ParsingException { HandlerEntry he = makeHandlerEntry(e); - if (e.getAttribute("default").equals("true")) { + if ("true".equals(e.getAttribute("default"))) { f.setDefaultCommandHandler(he); } else { Class command = parseCommandClass(e.getAttribute("command")); @@ -156,13 +156,13 @@ private static void parsePollHandler(Element e, FeatureTemplate f) throws Parsin } private static Class parseCommandClass(String c) throws ParsingException { - if (c.equals("OnOffType")) { + if ("OnOffType".equals(c)) { return OnOffType.class; - } else if (c.equals("PercentType")) { + } else if ("PercentType".equals(c)) { return PercentType.class; - } else if (c.equals("DecimalType")) { + } else if ("DecimalType".equals(c)) { return DecimalType.class; - } else if (c.equals("IncreaseDecreaseType")) { + } else if ("IncreaseDecreaseType".equals(c)) { return IncreaseDecreaseType.class; } else { throw new ParsingException("Unknown Command Type"); diff --git a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/MessageHandler.java b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/MessageHandler.java index 3faf7307e1edb..a01db6f6f0613 100644 --- a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/MessageHandler.java +++ b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/device/MessageHandler.java @@ -1078,9 +1078,9 @@ public void handleMessage(int group, byte cmd1, Msg msg, DeviceFeature f) { @Nullable State state; String scale = getStringParameter("scale", null); - if (scale != null && scale.equals("celsius")) { + if ("celsius".equals(scale)) { state = new QuantityType<>(dvalue, SIUnits.CELSIUS); - } else if (scale != null && scale.equals("fahrenheit")) { + } else if ("fahrenheit".equals(scale)) { state = new QuantityType<>(dvalue, ImperialUnits.FAHRENHEIT); } else { state = new DecimalType(dvalue); @@ -1102,7 +1102,7 @@ private int extractValue(Msg msg, int group) throws FieldException { return 0; } int value = 0; - if (lowByte.equals("group")) { + if ("group".equals(lowByte)) { value = group; } else { value = msg.getByte(lowByte) & 0xFF; diff --git a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/driver/SerialIOStream.java b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/driver/SerialIOStream.java index 746a5b1f203a0..f9b953cc63672 100644 --- a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/driver/SerialIOStream.java +++ b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/driver/SerialIOStream.java @@ -58,7 +58,7 @@ public SerialIOStream(@Nullable SerialPortManager serialPortManager, String conf } else { String key = paramParts[0]; String value = paramParts[1]; - if (key.equals("baudRate")) { + if ("baudRate".equals(key)) { try { baudRate = Integer.parseInt(value); } catch (NumberFormatException e) { diff --git a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/handler/InsteonNetworkHandler.java b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/handler/InsteonNetworkHandler.java index 708693dbb38b5..cea0cd66f4bdb 100644 --- a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/handler/InsteonNetworkHandler.java +++ b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/handler/InsteonNetworkHandler.java @@ -52,7 +52,6 @@ public class InsteonNetworkHandler extends BaseBridgeHandler { private final Logger logger = LoggerFactory.getLogger(InsteonNetworkHandler.class); - private @Nullable InsteonNetworkConfiguration config; private @Nullable InsteonBinding insteonBinding; private @Nullable InsteonDeviceDiscoveryService insteonDeviceDiscoveryService; private @Nullable ScheduledFuture pollingJob = null; @@ -77,17 +76,9 @@ public void handleCommand(ChannelUID channelUID, Command command) { @Override public void initialize() { logger.debug("Starting Insteon bridge"); - config = getConfigAs(InsteonNetworkConfiguration.class); + InsteonNetworkConfiguration config = getConfigAs(InsteonNetworkConfiguration.class); 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; if (serialPortManager == null) { String msg = "Initialization failed, serial port manager is null.";