Skip to content

Commit

Permalink
[insteon] Fix SAT warnings (openhab#10688)
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Nielsen <[email protected]>
  • Loading branch information
robnielsen authored and thinkingstone committed Nov 7, 2021
1 parent 6881e97 commit e9ec897
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
Expand All @@ -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())) {
Expand All @@ -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);
Expand All @@ -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));
}
}
Expand All @@ -191,16 +192,6 @@ private String processFeatureGroup(DeviceType devType, Element e) throws SAXExce
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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static List<FeatureTemplate> 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));
}
}
Expand Down Expand Up @@ -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");
Expand All @@ -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<? extends Command> command = parseCommandClass(e.getAttribute("command"));
Expand All @@ -156,13 +156,13 @@ private static void parsePollHandler(Element e, FeatureTemplate f) throws Parsin
}

private static Class<? extends Command> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.";
Expand Down

0 comments on commit e9ec897

Please sign in to comment.