From fec7b936a99d800d2e243cf3a06ee09137565744 Mon Sep 17 00:00:00 2001 From: Martin Herbst Date: Mon, 8 Feb 2021 23:26:56 +0100 Subject: [PATCH] [Homematic] Removed Apache Commons (#10035) Signed-off-by: Martin Herbst --- .../internal/common/HomematicConfig.java | 18 ++--- .../AbstractHomematicGateway.java | 3 +- .../internal/communicator/CcuGateway.java | 25 ++++--- .../communicator/client/RpcClient.java | 18 ++--- .../communicator/message/BinRpcMessage.java | 8 ++- .../communicator/message/XmlRpcRequest.java | 30 +++++++- .../parser/CcuParamsetDescriptionParser.java | 3 +- .../parser/CcuVariablesAndScriptsParser.java | 4 +- .../communicator/parser/CommonRpcParser.java | 36 ++++++---- .../parser/DeleteDevicesParser.java | 7 +- .../parser/DisplayOptionsParser.java | 36 +++++++--- .../communicator/parser/EventParser.java | 7 +- .../parser/GetAllScriptsParser.java | 4 +- .../parser/ListBidcosInterfacesParser.java | 2 +- .../parser/ListDevicesParser.java | 5 +- .../communicator/parser/NewDevicesParser.java | 6 +- .../parser/RpcResponseParser.java | 5 +- .../server/RpcResponseHandler.java | 4 +- .../ButtonVirtualDatapointHandler.java | 5 +- ...leteDeviceModeVirtualDatapointHandler.java | 3 +- ...DisplayOptionsVirtualDatapointHandler.java | 6 +- .../virtual/DisplayTextVirtualDatapoint.java | 15 ++-- .../discovery/eq3udp/Eq3UdpResponse.java | 7 +- .../handler/HomematicThingHandler.java | 22 +++--- .../homematic/internal/misc/MiscUtils.java | 58 +++++++++++++++ .../homematic/internal/model/HmChannel.java | 5 +- .../homematic/internal/model/HmDatapoint.java | 14 ++-- .../internal/model/HmDatapointConfig.java | 6 +- .../internal/model/HmDatapointInfo.java | 9 ++- .../homematic/internal/model/HmDevice.java | 14 ++-- .../internal/model/HmGatewayInfo.java | 10 +-- .../homematic/internal/model/HmRssiInfo.java | 6 +- .../type/HomematicTypeGeneratorImpl.java | 23 +++--- .../internal/type/MetadataUtils.java | 39 +++++++---- .../homematic/internal/type/UidUtils.java | 12 +++- .../type/generator/CcuMetadataExtractor.java | 70 ++++++++++--------- 36 files changed, 319 insertions(+), 226 deletions(-) diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/common/HomematicConfig.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/common/HomematicConfig.java index d90cc66addb26..f8ca3f7bc06c8 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/common/HomematicConfig.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/common/HomematicConfig.java @@ -12,8 +12,6 @@ */ package org.openhab.binding.homematic.internal.common; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; import org.openhab.binding.homematic.internal.model.HmChannel; import org.openhab.binding.homematic.internal.model.HmGatewayInfo; import org.openhab.binding.homematic.internal.model.HmInterface; @@ -405,14 +403,12 @@ public boolean isNoCCUType() { @Override public String toString() { - ToStringBuilder tsb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); - tsb.append("gatewayAddress", gatewayAddress).append("callbackHost", callbackHost) - .append("bindAddress", bindAddress).append("xmlCallbackPort", xmlCallbackPort) - .append("binCallbackPort", binCallbackPort).append("gatewayType", gatewayType) - .append("rfPort", getRfPort()).append("wiredPort", getWiredPort()).append("hmIpPort", getHmIpPort()) - .append("cuxdPort", getCuxdPort()).append("groupPort", getGroupPort()).append("timeout", timeout) - .append("discoveryTimeToLive", discoveryTimeToLive).append("installModeDuration", installModeDuration) - .append("socketMaxAlive", socketMaxAlive); - return tsb.toString(); + return String.format( + "%s[gatewayAddress=%s,callbackHost=%s,bindAddress=%s,xmlCallbackPort=%d,binCallbackPort=%d," + + "gatewayType=%s,rfPort=%d,wiredPort=%d,hmIpPort=%d,cuxdPort=%d,groupPort=%d,timeout=%d," + + "discoveryTimeToLive=%d,installModeDuration=%d,socketMaxAlive=%d]", + getClass().getSimpleName(), gatewayAddress, callbackHost, bindAddress, xmlCallbackPort, binCallbackPort, + gatewayType, getRfPort(), getWiredPort(), getHmIpPort(), getCuxdPort(), getGroupPort(), timeout, + discoveryTimeToLive, installModeDuration, socketMaxAlive); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/AbstractHomematicGateway.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/AbstractHomematicGateway.java index cf4d59f5b09b7..d834ec1f89f76 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/AbstractHomematicGateway.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/AbstractHomematicGateway.java @@ -29,7 +29,6 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import org.apache.commons.lang.StringUtils; import org.eclipse.jetty.client.HttpClient; import org.openhab.binding.homematic.internal.common.HomematicConfig; import org.openhab.binding.homematic.internal.communicator.client.BinRpcClient; @@ -800,7 +799,7 @@ public HomematicGatewayAdapter getGatewayAdapter() { * Creates a virtual device for handling variables, scripts and other special gateway functions. */ private HmDevice createGatewayDevice() { - String type = String.format("%s-%s", HmDevice.TYPE_GATEWAY_EXTRAS, StringUtils.upperCase(id)); + String type = String.format("%s-%s", HmDevice.TYPE_GATEWAY_EXTRAS, id.toUpperCase()); HmDevice device = new HmDevice(HmDevice.ADDRESS_GATEWAY_EXTRAS, getDefaultInterface(), type, config.getGatewayInfo().getId(), null, null); device.setName(HmDevice.TYPE_GATEWAY_EXTRAS); diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/CcuGateway.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/CcuGateway.java index 7e3835611cab8..5810194cd420e 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/CcuGateway.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/CcuGateway.java @@ -18,10 +18,9 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.concurrent.TimeUnit; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang.StringUtils; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.util.StringContentProvider; @@ -123,7 +122,7 @@ protected void setChannelDatapointValues(HmChannel channel, HmParamsetType param HmDevice device = channel.getDevice(); String channelName = String.format("%s.%s:%s.", device.getHmInterface().getName(), device.getAddress(), channel.getNumber()); - String datapointNames = StringUtils.join(dpNames.toArray(), "\\t"); + String datapointNames = String.join("\\t", dpNames); TclScriptDataList resultList = sendScriptByName("getAllChannelValues", TclScriptDataList.class, new String[] { "channel_name", "datapoint_names" }, new String[] { channelName, datapointNames }); @@ -151,7 +150,7 @@ protected void addChannelDatapoints(HmChannel channel, HmParamsetType paramsetTy @Override protected void setVariable(HmDatapoint dp, Object value) throws IOException { - String strValue = StringUtils.replace(ObjectUtils.toString(value), "\"", "\\\""); + String strValue = Objects.toString(value, "").replace("\"", "\\\""); if (dp.isStringType()) { strValue = "\"" + strValue + "\""; } @@ -184,8 +183,10 @@ private T sendScriptByName(String scriptName, Class clazz) throws IOExcep private T sendScriptByName(String scriptName, Class clazz, String[] variableNames, String[] values) throws IOException { String script = tclregaScripts.get(scriptName); - for (int i = 0; i < variableNames.length; i++) { - script = StringUtils.replace(script, "{" + variableNames[i] + "}", values[i]); + if (script != null) { + for (int i = 0; i < variableNames.length; i++) { + script = script.replace("{" + variableNames[i] + "}", values[i]); + } } return sendScript(script, clazz); } @@ -196,8 +197,8 @@ private T sendScriptByName(String scriptName, Class clazz, String[] varia @SuppressWarnings("unchecked") private synchronized T sendScript(String script, Class clazz) throws IOException { try { - script = StringUtils.trim(script); - if (StringUtils.isEmpty(script)) { + script = script == null ? null : script.trim(); + if (script == null || script.isEmpty()) { throw new RuntimeException("Homematic TclRegaScript is empty!"); } if (logger.isTraceEnabled()) { @@ -210,7 +211,10 @@ private synchronized T sendScript(String script, Class clazz) throws IOEx .header(HttpHeader.CONTENT_TYPE, "text/plain;charset=" + config.getEncoding()).send(); String result = new String(response.getContent(), config.getEncoding()); - result = StringUtils.substringBeforeLast(result, ""); + int lastPos = result.lastIndexOf(""); + if (lastPos != -1) { + result = result.substring(0, lastPos); + } if (logger.isTraceEnabled()) { logger.trace("Result TclRegaScript: {}", result); } @@ -231,7 +235,8 @@ private Map loadTclRegaScripts() throws IOException { Map result = new HashMap<>(); if (scriptList.getScripts() != null) { for (TclScript script : scriptList.getScripts()) { - result.put(script.name, StringUtils.trimToNull(script.data)); + String value = script.data.trim(); + result.put(script.name, value.isEmpty() ? null : value); } } return result; diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/client/RpcClient.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/client/RpcClient.java index 244c1891c4707..4f2fab2c823c9 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/client/RpcClient.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/client/RpcClient.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; -import org.apache.commons.lang.StringUtils; import org.openhab.binding.homematic.internal.HomematicBindingConstants; import org.openhab.binding.homematic.internal.common.HomematicConfig; import org.openhab.binding.homematic.internal.communicator.message.RpcRequest; @@ -34,6 +33,7 @@ import org.openhab.binding.homematic.internal.communicator.parser.ListBidcosInterfacesParser; import org.openhab.binding.homematic.internal.communicator.parser.ListDevicesParser; import org.openhab.binding.homematic.internal.communicator.parser.RssiInfoParser; +import org.openhab.binding.homematic.internal.misc.MiscUtils; import org.openhab.binding.homematic.internal.model.HmChannel; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmDevice; @@ -233,7 +233,7 @@ public HmGatewayInfo getGatewayInfo(String id) throws IOException { try { ddParser = getDeviceDescription(HmInterface.RF); - isHomegear = StringUtils.equalsIgnoreCase(ddParser.getType(), "Homegear"); + isHomegear = "Homegear".equalsIgnoreCase(ddParser.getType()); } catch (IOException ex) { // can't load gateway infos via RF interface ddParser = new GetDeviceDescriptionParser(); @@ -247,21 +247,23 @@ public HmGatewayInfo getGatewayInfo(String id) throws IOException { HmGatewayInfo gatewayInfo = new HmGatewayInfo(); gatewayInfo.setAddress(biParser.getGatewayAddress()); + String gwType = biParser.getType(); if (isHomegear) { gatewayInfo.setId(HmGatewayInfo.ID_HOMEGEAR); gatewayInfo.setType(ddParser.getType()); gatewayInfo.setFirmware(ddParser.getFirmware()); - } else if ((StringUtils.startsWithIgnoreCase(biParser.getType(), "CCU") - || StringUtils.startsWithIgnoreCase(biParser.getType(), "HMIP_CCU") - || StringUtils.startsWithIgnoreCase(ddParser.getType(), "HM-RCV-50") || config.isCCUType()) + } else if ((MiscUtils.strStartsWithIgnoreCase(gwType, "CCU") + || MiscUtils.strStartsWithIgnoreCase(gwType, "HMIP_CCU") + || MiscUtils.strStartsWithIgnoreCase(ddParser.getType(), "HM-RCV-50") || config.isCCUType()) && !config.isNoCCUType()) { gatewayInfo.setId(HmGatewayInfo.ID_CCU); - String type = StringUtils.isBlank(biParser.getType()) ? "CCU" : biParser.getType(); + String type = gwType.isBlank() ? "CCU" : gwType; gatewayInfo.setType(type); - gatewayInfo.setFirmware(ddParser.getFirmware() != null ? ddParser.getFirmware() : biParser.getFirmware()); + gatewayInfo + .setFirmware(!ddParser.getFirmware().isEmpty() ? ddParser.getFirmware() : biParser.getFirmware()); } else { gatewayInfo.setId(HmGatewayInfo.ID_DEFAULT); - gatewayInfo.setType(biParser.getType()); + gatewayInfo.setType(gwType); gatewayInfo.setFirmware(biParser.getFirmware()); } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/BinRpcMessage.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/BinRpcMessage.java index 8f7b3b36849e8..a94f38d2d4490 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/BinRpcMessage.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/BinRpcMessage.java @@ -29,7 +29,6 @@ import java.util.Map; import java.util.TreeMap; -import org.apache.commons.lang.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,7 +83,7 @@ public BinRpcMessage(InputStream is, boolean methodHeader, String encoding) thro if (length != 4) { throw new EOFException("Only " + length + " bytes received reading message length"); } - int datasize = (new BigInteger(ArrayUtils.subarray(sig, 4, 8))).intValue(); + int datasize = (new BigInteger(Arrays.copyOfRange(sig, 4, 8))).intValue(); byte payload[] = new byte[datasize]; int offset = 0; int currentLength; @@ -96,7 +95,10 @@ public BinRpcMessage(InputStream is, boolean methodHeader, String encoding) thro throw new EOFException("Only " + offset + " bytes received while reading message payload, expected " + datasize + " bytes"); } - byte[] message = ArrayUtils.addAll(sig, payload); + byte[] message = new byte[sig.length + payload.length]; + System.arraycopy(sig, 0, message, 0, sig.length); + System.arraycopy(payload, 0, message, sig.length, payload.length); + decodeMessage(message, methodHeader); } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/XmlRpcRequest.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/XmlRpcRequest.java index 43ea90b47c727..874ed7d560701 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/XmlRpcRequest.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/XmlRpcRequest.java @@ -23,8 +23,6 @@ import java.util.Map; import java.util.Map.Entry; -import org.apache.commons.lang.StringEscapeUtils; - /** * A XML-RPC request for sending data to the Homematic server. * @@ -124,7 +122,7 @@ private void generateValue(Object value) { } else { Class clazz = value.getClass(); if (clazz == String.class || clazz == Character.class) { - sb.append(StringEscapeUtils.escapeXml(value.toString())); + sb.append(escapeXml(value.toString())); } else if (clazz == Long.class || clazz == Integer.class || clazz == Short.class || clazz == Byte.class) { tag("int", value.toString()); } else if (clazz == Double.class) { @@ -176,4 +174,30 @@ private void generateValue(Object value) { } } } + + private StringBuilder escapeXml(String inValue) { + StringBuilder outValue = new StringBuilder(inValue.length()); + for (int i = 0; i < inValue.length(); i++) { + switch (inValue.charAt(i)) { + case '<': + outValue.append("<"); + break; + case '>': + outValue.append(">"); + break; + case '&': + outValue.append("&"); + break; + case '\'': + outValue.append("&apost;"); + break; + case '"': + outValue.append("""); + break; + default: + outValue.append(inValue.charAt(i)); + } + } + return outValue; + } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CcuParamsetDescriptionParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CcuParamsetDescriptionParser.java index ec35af77bdb21..84badc29fefe5 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CcuParamsetDescriptionParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CcuParamsetDescriptionParser.java @@ -14,7 +14,6 @@ import java.io.IOException; -import org.apache.commons.lang.StringUtils; import org.openhab.binding.homematic.internal.model.HmChannel; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmInterface; @@ -52,7 +51,7 @@ public Void parse(TclScriptDataList resultList) throws IOException { } private String[] toOptionList(String options) { - String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(options, ";"); + String[] result = options == null ? null : options.split(";"); return result == null || result.length == 0 ? null : result; } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CcuVariablesAndScriptsParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CcuVariablesAndScriptsParser.java index 4795120a3422c..17ff956ede68f 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CcuVariablesAndScriptsParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CcuVariablesAndScriptsParser.java @@ -14,7 +14,6 @@ import java.io.IOException; -import org.apache.commons.lang.StringUtils; import org.openhab.binding.homematic.internal.model.HmChannel; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmParamsetType; @@ -57,8 +56,7 @@ public Void parse(TclScriptDataList resultList) throws IOException { } dp.setReadOnly(entry.readOnly); dp.setUnit(entry.unit); - - String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(entry.options, ";"); + String[] result = entry.options == null ? null : entry.options.split(";"); dp.setOptions(result == null || result.length == 0 ? null : result); if (dp.getOptions() != null) { diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CommonRpcParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CommonRpcParser.java index aa87ae4e2cf0f..2196ea2ce216f 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CommonRpcParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CommonRpcParser.java @@ -13,11 +13,9 @@ package org.openhab.binding.homematic.internal.communicator.parser; import java.io.IOException; +import java.util.Objects; -import org.apache.commons.lang.BooleanUtils; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.math.NumberUtils; +import org.eclipse.jdt.annotation.NonNull; import org.openhab.binding.homematic.internal.misc.MiscUtils; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmParamsetType; @@ -38,7 +36,8 @@ public abstract class CommonRpcParser implements RpcParser { * Converts the object to a string. */ protected String toString(Object object) { - return StringUtils.trimToNull(ObjectUtils.toString(object)); + String value = Objects.toString(object, "").trim(); + return value.isEmpty() ? null : value; } /** @@ -49,7 +48,7 @@ protected Integer toInteger(Object object) { return (Integer) object; } try { - return Double.valueOf(ObjectUtils.toString(object)).intValue(); + return Double.valueOf(object.toString()).intValue(); } catch (NumberFormatException ex) { logger.debug("Failed converting {} to a Double", object, ex); return null; @@ -64,7 +63,7 @@ protected Double toDouble(Object object) { return (Double) object; } try { - return Double.valueOf(ObjectUtils.toString(object)); + return Double.valueOf(object.toString()); } catch (NumberFormatException ex) { logger.debug("Failed converting {} to a Double", object, ex); return null; @@ -79,7 +78,12 @@ protected Number toNumber(Object object) { return (Number) object; } try { - return NumberUtils.createNumber(ObjectUtils.toString(object)); + String value = object.toString(); + if (value.contains(".")) { + return Float.parseFloat(value); + } else { + return Integer.parseInt(value); + } } catch (NumberFormatException ex) { logger.debug("Failed converting {} to a Number", object, ex); return null; @@ -93,7 +97,7 @@ protected Boolean toBoolean(Object object) { if (object == null || object instanceof Boolean) { return (Boolean) object; } - return BooleanUtils.toBoolean(ObjectUtils.toString(object)); + return "true".equals(object.toString().toLowerCase()); } /** @@ -114,9 +118,10 @@ protected String[] toOptionList(Object optionList) { /** * Returns the address of a device, replacing group address identifier and illegal characters. */ + @NonNull protected String getSanitizedAddress(Object object) { - String address = StringUtils.trimToNull(StringUtils.replaceOnce(toString(object), "*", "T-")); - return MiscUtils.validateCharacters(address, "Address", "_"); + String address = Objects.toString(object, "").trim().replaceFirst("\\*", "T-"); + return MiscUtils.validateCharacters(address.isEmpty() ? null : address, "Address", "_"); } /** @@ -167,8 +172,11 @@ protected HmDatapoint assembleDatapoint(String name, String unit, String type, S HmDatapoint dp = new HmDatapoint(); dp.setName(name); dp.setDescription(name); - dp.setUnit(StringUtils.replace(StringUtils.trimToNull(unit), "\ufffd", "°")); - if (dp.getUnit() == null && StringUtils.startsWith(dp.getName(), "RSSI_")) { + if (unit != null) { + unit = unit.trim().replace("\ufffd", "°"); + } + dp.setUnit(unit == null || unit.isEmpty() ? null : unit); + if (dp.getUnit() == null && dp.getName() != null && dp.getName().startsWith("RSSI_")) { dp.setUnit("dBm"); } @@ -210,7 +218,7 @@ protected HmDatapoint assembleDatapoint(String name, String unit, String type, S * Converts a string value to the type. */ protected Object convertToType(String value) { - if (StringUtils.isBlank(value)) { + if (value == null || value.isBlank()) { return null; } if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("on")) { diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/DeleteDevicesParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/DeleteDevicesParser.java index d038b78f65797..5a7701b2e09ae 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/DeleteDevicesParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/DeleteDevicesParser.java @@ -16,7 +16,7 @@ import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang.StringUtils; +import org.openhab.binding.homematic.internal.misc.MiscUtils; /** * Parses a delete device event received from a Homematic gateway. @@ -31,12 +31,9 @@ public List parse(Object[] message) throws IOException { Object[] data = (Object[]) message[1]; for (int i = 0; i < message.length; i++) { String address = getSanitizedAddress(data[i]); - boolean isDevice = !StringUtils.contains(address, ":") - && !StringUtils.startsWithIgnoreCase(address, "BidCos"); - if (isDevice) { + if (MiscUtils.isDevice(address)) { adresses.add(address); } - } } return adresses; diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/DisplayOptionsParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/DisplayOptionsParser.java index 9ad2bbb92db37..6ee848e4db7f6 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/DisplayOptionsParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/DisplayOptionsParser.java @@ -16,10 +16,9 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; import org.openhab.binding.homematic.internal.model.HmChannel; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmDatapointInfo; @@ -36,7 +35,7 @@ public class DisplayOptionsParser extends CommonRpcParser { private final Logger logger = LoggerFactory.getLogger(DisplayOptionsParser.class); private static final String[] onOff = new String[] { "ON", "OFF" }; - + private static final int IDX_NOT_FOUND = -1; private HmChannel channel; private String text; private int beep = 0; @@ -50,7 +49,8 @@ public DisplayOptionsParser(HmChannel channel) { @Override public Void parse(Object value) throws IOException { - String optionsString = StringUtils.remove(toString(value), ' '); + String valueString = toString(value); + String optionsString = valueString == null ? null : valueString.replace(" ", ""); if (optionsString != null) { int idxFirstSep = optionsString.indexOf(","); if (idxFirstSep == -1) { @@ -61,7 +61,7 @@ public Void parse(Object value) throws IOException { optionsString = optionsString.substring(idxFirstSep + 1); } - String[] options = StringUtils.split(optionsString, ","); + String[] options = optionsString.split(","); String[] availableSymbols = getAvailableSymbols(channel); String[] availableBeepOptions = getAvailableOptions(channel, DATAPOINT_NAME_BEEP); @@ -87,7 +87,7 @@ public Void parse(Object value) throws IOException { DATAPOINT_NAME_BACKLIGHT, deviceAddress); unit = getIntParameter(availableUnitOptions, unit, parameter, DATAPOINT_NAME_UNIT, deviceAddress); - if (ArrayUtils.contains(availableSymbols, parameter)) { + if (findInArray(availableSymbols, parameter) != IDX_NOT_FOUND) { logger.debug("Symbol '{}' found for remote control '{}'", parameter, deviceAddress); symbols.add(parameter); } @@ -102,8 +102,8 @@ public Void parse(Object value) throws IOException { */ private int getIntParameter(String[] options, int currentValue, String parameter, String parameterName, String deviceAddress) { - int idx = ArrayUtils.indexOf(options, parameter); - if (idx != -1) { + int idx = findInArray(options, parameter); + if (idx != IDX_NOT_FOUND) { if (currentValue == 0) { logger.debug("{} option '{}' found at index {} for remote control '{}'", parameterName, parameter, idx + 1, deviceAddress); @@ -125,10 +125,12 @@ private String[] getAvailableOptions(HmChannel channel, String datapointName) { HmDatapointInfo dpInfo = HmDatapointInfo.createValuesInfo(channel, datapointName); HmDatapoint dp = channel.getDatapoint(dpInfo); if (dp != null) { - String[] options = (String[]) ArrayUtils.remove(dp.getOptions(), 0); + String[] dpOpts = dp.getOptions(); + String[] options = new String[dpOpts.length - 1]; + options = Arrays.copyOfRange(dpOpts, 1, dpOpts.length); for (String onOffString : onOff) { - int onIdx = ArrayUtils.indexOf(options, onOffString); - if (onIdx != -1) { + int onIdx = findInArray(options, onOffString); + if (onIdx != IDX_NOT_FOUND) { options[onIdx] = datapointName + "_" + onOffString; } } @@ -137,6 +139,18 @@ private String[] getAvailableOptions(HmChannel channel, String datapointName) { return new String[0]; } + private int findInArray(String[] arr, String searchString) { + if (arr.length == 0) { + return IDX_NOT_FOUND; + } + for (int i = 0; i < arr.length; i++) { + if (arr[i].equals(searchString)) { + return i; + } + } + return IDX_NOT_FOUND; + } + /** * Returns all possible symbols from the remote control. */ diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/EventParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/EventParser.java index 237bc28373ebd..7cf06ce6863d7 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/EventParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/EventParser.java @@ -14,8 +14,6 @@ import java.io.IOException; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.math.NumberUtils; import org.openhab.binding.homematic.internal.model.HmChannel; import org.openhab.binding.homematic.internal.model.HmDatapointInfo; import org.openhab.binding.homematic.internal.model.HmDevice; @@ -38,10 +36,11 @@ public HmDatapointInfo parse(Object[] message) throws IOException { address = HmDevice.ADDRESS_GATEWAY_EXTRAS; channel = HmChannel.CHANNEL_NUMBER_VARIABLE; } else { - String[] configParts = StringUtils.trimToEmpty(addressWithChannel).split(":"); + String addrChannel = addressWithChannel == null ? "" : addressWithChannel.trim(); + String[] configParts = addrChannel.split(":"); address = getSanitizedAddress(configParts[0]); if (configParts.length > 1) { - channel = NumberUtils.createInteger(configParts[1]); + channel = configParts[1] == null ? null : Integer.valueOf(configParts[1]); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/GetAllScriptsParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/GetAllScriptsParser.java index d33229280b3b8..14b11cb185378 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/GetAllScriptsParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/GetAllScriptsParser.java @@ -13,8 +13,8 @@ package org.openhab.binding.homematic.internal.communicator.parser; import java.io.IOException; +import java.util.Objects; -import org.apache.commons.lang.ObjectUtils; import org.openhab.binding.homematic.internal.model.HmChannel; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmParamsetType; @@ -36,7 +36,7 @@ public GetAllScriptsParser(HmChannel channel) { public Void parse(Object[] message) throws IOException { message = (Object[]) message[0]; for (int i = 0; i < message.length; i++) { - String scriptName = ObjectUtils.toString(message[i]); + String scriptName = Objects.toString(message[i], ""); HmDatapoint dpScript = new HmDatapoint(scriptName, scriptName, HmValueType.BOOL, Boolean.FALSE, false, HmParamsetType.VALUES); dpScript.setInfo(scriptName); diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/ListBidcosInterfacesParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/ListBidcosInterfacesParser.java index 6c63dd5330166..53446f024cfea 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/ListBidcosInterfacesParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/ListBidcosInterfacesParser.java @@ -50,7 +50,7 @@ public ListBidcosInterfacesParser parse(Object[] message) throws IOException { * Returns the parsed type. */ public String getType() { - return type; + return type == null ? "" : type; } /** diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/ListDevicesParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/ListDevicesParser.java index 41e168f1b0604..fb1ee5cffc35d 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/ListDevicesParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/ListDevicesParser.java @@ -19,7 +19,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.commons.lang.StringUtils; import org.openhab.binding.homematic.internal.common.HomematicConfig; import org.openhab.binding.homematic.internal.misc.MiscUtils; import org.openhab.binding.homematic.internal.model.HmChannel; @@ -48,9 +47,7 @@ public Collection parse(Object[] message) throws IOException { for (int i = 0; i < message.length; i++) { Map data = (Map) message[i]; - boolean isDevice = !StringUtils.contains(toString(data.get("ADDRESS")), ":"); - - if (isDevice) { + if (MiscUtils.isDevice(toString(data.get("ADDRESS")), true)) { String address = getSanitizedAddress(data.get("ADDRESS")); String type = MiscUtils.validateCharacters(toString(data.get("TYPE")), "Device type", "-"); String id = toString(data.get("ID")); diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/NewDevicesParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/NewDevicesParser.java index 92b97056692e9..8ec4bee27115b 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/NewDevicesParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/NewDevicesParser.java @@ -17,7 +17,7 @@ import java.util.List; import java.util.Map; -import org.apache.commons.lang.StringUtils; +import org.openhab.binding.homematic.internal.misc.MiscUtils; /** * Parses a new device event received from a Homematic gateway. @@ -35,9 +35,7 @@ public List parse(Object[] message) throws IOException { Map data = (Map) message[i]; String address = toString(data.get("ADDRESS")); - boolean isDevice = !StringUtils.contains(address, ":") - && !StringUtils.startsWithIgnoreCase(address, "BidCos"); - if (isDevice) { + if (MiscUtils.isDevice(address)) { adresses.add(getSanitizedAddress(address)); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/RpcResponseParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/RpcResponseParser.java index 241b48257d7de..ca796488e7c4e 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/RpcResponseParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/RpcResponseParser.java @@ -15,7 +15,6 @@ import java.io.IOException; import java.util.Map; -import org.apache.commons.lang.StringUtils; import org.openhab.binding.homematic.internal.communicator.client.UnknownParameterSetException; import org.openhab.binding.homematic.internal.communicator.client.UnknownRpcFailureException; import org.openhab.binding.homematic.internal.communicator.message.RpcRequest; @@ -43,9 +42,9 @@ public Object[] parse(Object[] message) throws IOException { Number faultCode = toNumber(map.get("faultCode")); String faultString = toString(map.get("faultString")); String faultMessage = String.format("%s %s (sending %s)", faultCode, faultString, request); - if (faultCode.intValue() == -1 && StringUtils.equals("Failure", faultString)) { + if (faultCode.intValue() == -1 && "Failure".equals(faultString)) { throw new UnknownRpcFailureException(faultMessage); - } else if (faultCode.intValue() == -3 && StringUtils.equals("Unknown paramset", faultString)) { + } else if (faultCode.intValue() == -3 && "Unknown paramset".equals(faultString)) { throw new UnknownParameterSetException(faultMessage); } throw new IOException(faultMessage); diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/server/RpcResponseHandler.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/server/RpcResponseHandler.java index 431f3e8bae1c2..010dc88df3700 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/server/RpcResponseHandler.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/server/RpcResponseHandler.java @@ -18,8 +18,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; -import org.apache.commons.lang.ObjectUtils; import org.openhab.binding.homematic.internal.communicator.message.RpcRequest; import org.openhab.binding.homematic.internal.communicator.parser.DeleteDevicesParser; import org.openhab.binding.homematic.internal.communicator.parser.EventParser; @@ -63,7 +63,7 @@ public T handleMethodCall(String methodName, Object[] responseData) throws IOExc for (Object o : (Object[]) responseData[0]) { Map call = (Map) o; if (call != null) { - String method = ObjectUtils.toString(call.get("methodName")); + String method = Objects.toString(call.get("methodName"), ""); Object[] data = (Object[]) call.get("params"); handleMethodCall(method, data); } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java index 43fce06e2fba5..b4feca685fad3 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java @@ -14,13 +14,13 @@ import static org.openhab.binding.homematic.internal.misc.HomematicConstants.VIRTUAL_DATAPOINT_NAME_BUTTON; -import org.apache.commons.lang.StringUtils; import org.openhab.binding.homematic.internal.misc.MiscUtils; import org.openhab.binding.homematic.internal.model.HmChannel; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmDevice; import org.openhab.binding.homematic.internal.model.HmValueType; import org.openhab.core.thing.CommonTriggerEvents; +import org.openhab.core.thing.DefaultSystemChannelTypeProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,7 +59,8 @@ public boolean canHandleEvent(HmDatapoint dp) { public void handleEvent(VirtualGateway gateway, HmDatapoint dp) { HmDatapoint vdp = getVirtualDatapoint(dp.getChannel()); if (MiscUtils.isTrueValue(dp.getValue())) { - String pressType = StringUtils.substringAfter(dp.getName(), "_"); + int usPos = dp.getName().indexOf("_"); + String pressType = usPos == -1 ? dp.getName() : dp.getName().substring(usPos + 1); switch (pressType) { case "SHORT": if (dp.getValue() == null || !dp.getValue().equals(dp.getPreviousValue())) { diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/DeleteDeviceModeVirtualDatapointHandler.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/DeleteDeviceModeVirtualDatapointHandler.java index dbbaf8bac314c..c79263dd57a8d 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/DeleteDeviceModeVirtualDatapointHandler.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/DeleteDeviceModeVirtualDatapointHandler.java @@ -16,7 +16,6 @@ import java.io.IOException; -import org.apache.commons.lang.StringUtils; import org.openhab.binding.homematic.internal.misc.HomematicClientException; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmDatapointConfig; @@ -61,7 +60,7 @@ public boolean canHandleCommand(HmDatapoint dp, Object value) { public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value) throws IOException, HomematicClientException { dp.setValue(value); - if (!StringUtils.equals(dp.getOptionValue(), MODE_LOCKED)) { + if (!MODE_LOCKED.equals(dp.getOptionValue())) { gateway.disableDatapoint(dp, DELETE_MODE_DURATION); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/DisplayOptionsVirtualDatapointHandler.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/DisplayOptionsVirtualDatapointHandler.java index ce45dcaa58994..eaf1a8b39e552 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/DisplayOptionsVirtualDatapointHandler.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/DisplayOptionsVirtualDatapointHandler.java @@ -16,7 +16,6 @@ import java.io.IOException; -import org.apache.commons.lang.StringUtils; import org.openhab.binding.homematic.internal.communicator.parser.DisplayOptionsParser; import org.openhab.binding.homematic.internal.misc.HomematicClientException; import org.openhab.binding.homematic.internal.model.HmChannel; @@ -60,8 +59,9 @@ public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointCon DisplayOptionsParser rcOptionsParser = new DisplayOptionsParser(channel); rcOptionsParser.parse(value); - if (StringUtils.isNotBlank(rcOptionsParser.getText())) { - sendDatapoint(gateway, channel, DATAPOINT_NAME_TEXT, rcOptionsParser.getText()); + String dpNameText = rcOptionsParser.getText(); + if (dpNameText != null && !dpNameText.isBlank()) { + sendDatapoint(gateway, channel, DATAPOINT_NAME_TEXT, dpNameText); } sendDatapoint(gateway, channel, DATAPOINT_NAME_BEEP, rcOptionsParser.getBeep()); diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/DisplayTextVirtualDatapoint.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/DisplayTextVirtualDatapoint.java index 4c33ae02337ec..8a23ecb4423e3 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/DisplayTextVirtualDatapoint.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/DisplayTextVirtualDatapoint.java @@ -21,9 +21,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang.StringUtils; import org.openhab.binding.homematic.internal.misc.HomematicClientException; import org.openhab.binding.homematic.internal.misc.MiscUtils; import org.openhab.binding.homematic.internal.model.HmChannel; @@ -328,9 +327,9 @@ public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointCon } for (int i = 1; i <= getLineCount(channel.getDevice()); i++) { - String line = ObjectUtils.toString( - channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_LINE + i).getValue()); - if (StringUtils.isEmpty(line)) { + String line = Objects.toString( + channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_LINE + i).getValue(), ""); + if (line.isEmpty()) { line = " "; } message.add(LINE); @@ -340,12 +339,12 @@ public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointCon .getOptionValue(); message.add(COLOR); String colorCode = Color.getCode(color); - message.add(StringUtils.isBlank(colorCode) ? Color.WHITE.getCode() : colorCode); + message.add(colorCode == null || colorCode.isBlank() ? Color.WHITE.getCode() : colorCode); } String icon = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_ICON + i) .getOptionValue(); String iconCode = Icon.getCode(icon); - if (StringUtils.isNotBlank(iconCode)) { + if (iconCode != null && !iconCode.isBlank()) { message.add(ICON); message.add(iconCode); } @@ -374,7 +373,7 @@ public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointCon message.add(STOP); gateway.sendDatapoint(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_SUBMIT), - new HmDatapointConfig(), StringUtils.join(message, ","), null); + new HmDatapointConfig(), String.join(",", message), null); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/discovery/eq3udp/Eq3UdpResponse.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/discovery/eq3udp/Eq3UdpResponse.java index 5a6dd08934aed..6956c049e5103 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/discovery/eq3udp/Eq3UdpResponse.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/discovery/eq3udp/Eq3UdpResponse.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.homematic.internal.discovery.eq3udp; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - /** * Extracts a UDP response from a Homematic CCU gateway. * @@ -86,7 +83,7 @@ private int readInt(byte[] data, int index, int length) throws IndexOutOfBoundsE @Override public String toString() { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("deviceTypeId", deviceTypeId) - .append("serialNumber", serialNumber).toString(); + return String.format("%s[deviceTypeId=%s,serialNumber=%s]", getClass().getSimpleName(), deviceTypeId, + serialNumber); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java index 0ac53954a681d..05bcf0048d875 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java @@ -23,11 +23,9 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.concurrent.Future; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.math.NumberUtils; import org.openhab.binding.homematic.internal.HomematicBindingConstants; import org.openhab.binding.homematic.internal.common.HomematicConfig; import org.openhab.binding.homematic.internal.communicator.HomematicGateway; @@ -216,8 +214,8 @@ private boolean updateDynamicChannelList(HmDevice device, List thingCha private static boolean containsChannel(List channels, ChannelUID channelUID) { for (Channel channel : channels) { ChannelUID uid = channel.getUID(); - if (StringUtils.equals(channelUID.getGroupId(), uid.getGroupId()) - && StringUtils.equals(channelUID.getId(), uid.getId())) { + if (Objects.equals(channelUID.getGroupId(), uid.getGroupId()) + && Objects.equals(channelUID.getId(), uid.getId())) { return true; } } @@ -232,7 +230,7 @@ private void setProperty(Map properties, HmChannel channelZero, HmDatapoint dp = channelZero .getDatapoint(new HmDatapointInfo(HmParamsetType.VALUES, channelZero, datapointName)); if (dp != null) { - properties.put(propertyName, ObjectUtils.toString(dp.getValue())); + properties.put(propertyName, Objects.toString(dp.getValue(), "")); } } @@ -375,7 +373,7 @@ private void updateChannelState(final HmDatapoint dp, Channel channel) throws IOException, GatewayNotAvailableException, ConverterException { if (dp.isTrigger()) { if (dp.getValue() != null) { - triggerChannel(channel.getUID(), ObjectUtils.toString(dp.getValue())); + triggerChannel(channel.getUID(), dp.getValue() == null ? "" : dp.getValue().toString()); } } else if (isLinked(channel)) { loadHomematicChannelValues(dp.getChannel()); @@ -495,9 +493,10 @@ public void handleConfigurationUpdate(Map configurationParameter Object newValue = configurationParameter.getValue(); if (key.startsWith("HMP_")) { - key = StringUtils.removeStart(key, "HMP_"); - Integer channelNumber = NumberUtils.toInt(StringUtils.substringBefore(key, "_")); - String dpName = StringUtils.substringAfter(key, "_"); + key = key.substring(4); + int sepPos = key.indexOf("_"); + Integer channelNumber = Integer.valueOf(key.substring(0, sepPos)); + String dpName = key.substring(sepPos + 1); HmDatapointInfo dpInfo = new HmDatapointInfo(device.getAddress(), HmParamsetType.MASTER, channelNumber, dpName); @@ -514,8 +513,7 @@ public void handleConfigurationUpdate(Map configurationParameter newValue = decimal.doubleValue(); } } - if (ObjectUtils.notEqual(dp.isEnumType() ? dp.getOptionValue() : dp.getValue(), - newValue)) { + if (!Objects.equals(dp.isEnumType() ? dp.getOptionValue() : dp.getValue(), newValue)) { sendDatapoint(dp, new HmDatapointConfig(), newValue); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/misc/MiscUtils.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/misc/MiscUtils.java index 20f54e5211460..d41aaad9e5a98 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/misc/MiscUtils.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/misc/MiscUtils.java @@ -50,4 +50,62 @@ public static boolean isTrueValue(Object value) { public static boolean isFalseValue(Object value) { return value != null && value == Boolean.FALSE; } + + /** + * Returns true, if str starts with search. Check is done case-insensitive. + */ + public static boolean strStartsWithIgnoreCase(String str, String search) { + if (str == null || search == null || search.length() > str.length()) { + return false; + } + return str.substring(0, search.length()).equalsIgnoreCase(search); + } + + /** + * Returns true if address is a device + */ + public static boolean isDevice(String address) { + return isDevice(address, false); + } + + /** + * Returns true if address is a device. If allowBidCos ist true then addresses starting with "BidCos" classified as + * devices, too. + */ + public static boolean isDevice(String address, boolean allowBidCos) { + if (address == null) { + return false; + } + if (address.contains(":")) { + return false; + } + if (allowBidCos && strStartsWithIgnoreCase(address.trim(), "BidCos")) { + return true; + } + return !strStartsWithIgnoreCase(address.trim(), "BidCos"); + } + + /** + * Changes all characters after whitespace to upper-case and all other character to lower case. + */ + public static String capitalize(String value) { + if (value == null) { + return null; + } + char[] chars = value.toCharArray(); + boolean capitalizeNextChar = true; + for (int i = 0; i < chars.length; i++) { + if (Character.isWhitespace(chars[i])) { + capitalizeNextChar = true; + } else { + if (capitalizeNextChar) { + chars[i] = Character.toTitleCase(chars[i]); + capitalizeNextChar = false; + } else { + chars[i] = Character.toLowerCase(chars[i]); + } + } + } + return new String(chars); + } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmChannel.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmChannel.java index 4214d73b558a1..75eece216b28a 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmChannel.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmChannel.java @@ -18,8 +18,6 @@ import java.util.List; import java.util.Map; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; import org.openhab.binding.homematic.internal.misc.HomematicConstants; /** @@ -216,7 +214,6 @@ public boolean hasPressDatapoint() { @Override public String toString() { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("number", number).append("type", type) - .append("initialized", initialized).toString(); + return String.format("%s[number=%d,initialized=%b]", getClass().getSimpleName(), number, initialized); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDatapoint.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDatapoint.java index d54d2f7fd43ce..7203179bf2765 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDatapoint.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDatapoint.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.homematic.internal.model; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; import org.openhab.binding.homematic.internal.misc.MiscUtils; /** @@ -431,11 +428,10 @@ public HmDatapoint clone() { @Override public String toString() { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("name", name).append("value", value) - .append("defaultValue", defaultValue).append("type", type).append("minValue", minValue) - .append("maxValue", maxValue).append("step", step).append("options", StringUtils.join(options, ";")) - .append("readOnly", readOnly).append("readable", readable).append("unit", unit) - .append("description", description).append("info", info).append("paramsetType", paramsetType) - .append("virtual", virtual).append("trigger", trigger).toString(); + return String.format("%s[name=%s,value=%s,defaultValue=%s,type=%s,minValue=%s,maxValue=%s,step=%s,options=%s," + + "readOnly=%b,readable=%b,unit=%s,description=%s,info=%s,paramsetType=%s,virtual=%b,trigger=%b]", + getClass().getSimpleName(), name, value, defaultValue, type, minValue, maxValue, step, + (options == null ? null : String.join(";", options)), readOnly, readable, unit, description, info, + paramsetType, virtual, trigger); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDatapointConfig.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDatapointConfig.java index 75c9a23a0225d..11f1a0eb021ed 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDatapointConfig.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDatapointConfig.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.homematic.internal.model; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - /** * Configuration object for sending a datapoint. * @@ -54,7 +51,6 @@ public void setReceiveDelay(Double receiveDelay) { @Override public String toString() { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("delay", delay) - .append("receiveDelay", receiveDelay).toString(); + return String.format("%s[delay=%f,receiveDelay=%f]", getClass().getSimpleName(), delay, receiveDelay); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDatapointInfo.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDatapointInfo.java index 67ac4a7bdc903..e0374d16243d0 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDatapointInfo.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDatapointInfo.java @@ -12,8 +12,7 @@ */ package org.openhab.binding.homematic.internal.model; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; +import java.util.Objects; /** * Simple representation of a datapoint. @@ -92,7 +91,7 @@ public boolean isPong() { @Override public int hashCode() { - return new HashCodeBuilder().append(address).append(paramsetType).append(channel).append(name).toHashCode(); + return Objects.hash(address, paramsetType, channel, name); } @Override @@ -101,8 +100,8 @@ public boolean equals(Object obj) { return false; } HmDatapointInfo comp = (HmDatapointInfo) obj; - return new EqualsBuilder().append(address, comp.getAddress()).append(paramsetType, comp.getParamsetType()) - .append(channel, comp.getChannel()).append(name, comp.getName()).isEquals(); + return Objects.equals(address, comp.getAddress()) && Objects.equals(paramsetType, comp.getParamsetType()) + && Objects.equals(channel, comp.getChannel()) && Objects.equals(name, comp.getName()); } @Override diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDevice.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDevice.java index 8f265ced3c2f4..abd814f5beb6b 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDevice.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDevice.java @@ -16,11 +16,8 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; import org.openhab.binding.homematic.internal.misc.MiscUtils; /** @@ -202,7 +199,7 @@ private boolean isStatusDatapointEnabled(String datapointName) { @Override public int hashCode() { - return new HashCodeBuilder().append(address).toHashCode(); + return Objects.hash(address); } @Override @@ -211,13 +208,12 @@ public boolean equals(Object obj) { return false; } HmDevice comp = (HmDevice) obj; - return new EqualsBuilder().append(address, comp.getAddress()).isEquals(); + return Objects.equals(address, comp.getAddress()); } @Override public String toString() { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("hmInterface", hmInterface) - .append("address", address).append("type", type).append("name", name).append("firmware", firmware) - .append("gatewayId", gatewayId).toString(); + return String.format("%s[hmInterface=%s,address=%s,type=%s,name=%s,firmware=%s,gatewayId=%s]", + getClass().getSimpleName(), hmInterface, address, type, name, firmware, gatewayId); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmGatewayInfo.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmGatewayInfo.java index 1bfbfb5b9c3b0..fc77be6b29d73 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmGatewayInfo.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmGatewayInfo.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.homematic.internal.model; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - /** * Info object which holds gateway specific informations. * @@ -184,9 +181,8 @@ public void setRfInterface(boolean rfInterface) { @Override public String toString() { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("id", id).append("type", type) - .append("firmware", firmware).append("address", address).append("rf", rfInterface) - .append("wired", wiredInterface).append("hmip", hmipInterface).append("cuxd", cuxdInterface) - .append("group", groupInterface).toString(); + return String.format("%s[id=%s,type=%s,firmware=%s,address=%s,rf=%b,wired=%b,hmip=%b,cuxd=%b,group=%b]", + getClass().getSimpleName(), id, type, firmware, address, rfInterface, wiredInterface, hmipInterface, + cuxdInterface, groupInterface); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmRssiInfo.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmRssiInfo.java index ebae8c1c5e13f..2978f4b921f77 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmRssiInfo.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmRssiInfo.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.homematic.internal.model; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - /** * Object that holds the rssi infos for a RF device. * @@ -65,7 +62,6 @@ public Integer getPeer() { @Override public String toString() { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("address", address) - .append("device", device).append("peer", peer).toString(); + return String.format("%s[address=%s,device=%d,peer=%i]", getClass().getSimpleName(), address, device, peer); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/HomematicTypeGeneratorImpl.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/HomematicTypeGeneratorImpl.java index ce10bca8e6113..a3ea8000e88e7 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/HomematicTypeGeneratorImpl.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/HomematicTypeGeneratorImpl.java @@ -23,11 +23,10 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.WordUtils; +import org.openhab.binding.homematic.internal.misc.MiscUtils; import org.openhab.binding.homematic.internal.model.HmChannel; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmDevice; @@ -171,7 +170,7 @@ public void generate(HmDevice device) { ChannelGroupType groupType = channelGroupTypeProvider.getInternalChannelGroupType(groupTypeUID); if (groupType == null || device.isGatewayExtras()) { String groupLabel = String.format("%s", - WordUtils.capitalizeFully(StringUtils.replace(channel.getType(), "_", " "))); + MiscUtils.capitalize(channel.getType().replace("_", " "))); groupType = ChannelGroupTypeBuilder.instance(groupTypeUID, groupLabel) .withChannelDefinitions(channelDefinitions).build(); channelGroupTypeProvider.addChannelGroupType(groupType); @@ -195,7 +194,7 @@ public void validateFirmwares() { "Multiple firmware versions for device type '{}' found ({}). " + "Make sure, all devices of the same type have the same firmware version, " + "otherwise you MAY have channel and/or datapoint errors in the logfile", - deviceType, StringUtils.join(firmwares, ", ")); + deviceType, String.join(", ", firmwares)); } } } @@ -204,7 +203,7 @@ public void validateFirmwares() { * Adds the firmware version for validation. */ private void addFirmware(HmDevice device) { - if (!StringUtils.equals(device.getFirmware(), "?") && !DEVICE_TYPE_VIRTUAL.equals(device.getType()) + if (!"?".equals(device.getFirmware()) && !DEVICE_TYPE_VIRTUAL.equals(device.getType()) && !DEVICE_TYPE_VIRTUAL_WIRED.equals(device.getType())) { Set firmwares = firmwaresByType.get(device.getType()); if (firmwares == null) { @@ -237,7 +236,8 @@ private ThingType createThingType(HmDevice device, List groupT List groupDefinitions = new ArrayList<>(); for (ChannelGroupType groupType : groupTypes) { - String id = StringUtils.substringAfterLast(groupType.getUID().getId(), "_"); + int usPos = groupType.getUID().getId().lastIndexOf("_"); + String id = usPos == -1 ? groupType.getUID().getId() : groupType.getUID().getId().substring(usPos + 1); groupDefinitions.add(new ChannelGroupDefinition(id, groupType.getUID())); } @@ -337,7 +337,7 @@ private void generateConfigDescription(HmDevice device, URI configDescriptionURI MetadataUtils.getParameterName(dp), MetadataUtils.getConfigDescriptionParameterType(dp)); builder.withLabel(MetadataUtils.getLabel(dp)); - builder.withDefault(ObjectUtils.toString(dp.getDefaultValue())); + builder.withDefault(Objects.toString(dp.getDefaultValue(), "")); builder.withDescription(MetadataUtils.getDatapointDescription(dp)); if (dp.isEnumType()) { @@ -383,6 +383,11 @@ private URI getConfigDescriptionURI(HmDevice device) { * Returns true, if the given datapoint can be ignored for metadata generation. */ public static boolean isIgnoredDatapoint(HmDatapoint dp) { - return StringUtils.indexOfAny(dp.getName(), IGNORE_DATAPOINT_NAMES) != -1; + for (String testValue : IGNORE_DATAPOINT_NAMES) { + if (dp.getName().indexOf(testValue) > -1) { + return true; + } + } + return false; } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java index ef5178b285fad..75e182667e8e1 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java @@ -21,6 +21,7 @@ import java.io.InputStreamReader; import java.math.BigDecimal; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -29,8 +30,7 @@ import java.util.ResourceBundle; import java.util.Set; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.WordUtils; +import org.openhab.binding.homematic.internal.misc.MiscUtils; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmDevice; import org.openhab.core.config.core.ConfigDescriptionParameter.Type; @@ -77,9 +77,16 @@ private static void loadStandardDatapoints() { BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) { String line; while ((line = reader.readLine()) != null) { - if (StringUtils.trimToNull(line) != null && !StringUtils.startsWith(line, "#")) { - String channelType = StringUtils.trimToNull(StringUtils.substringBefore(line, "|")); - String datapointName = StringUtils.trimToNull(StringUtils.substringAfter(line, "|")); + if (!line.trim().isEmpty() && !line.startsWith("#")) { + String[] parts = line.split("\\|"); + String channelType = null; + String datapointName = null; + if (parts.length > 0) { + channelType = parts[0].trim(); + if (parts.length > 1) { + datapointName = parts[1].trim(); + } + } Set channelDatapoints = standardDatapoints.get(channelType); if (channelDatapoints == null) { @@ -142,8 +149,7 @@ public static Type getConfigDescriptionParameterType(HmDatapoint dp) { */ public static String getUnit(HmDatapoint dp) { if (dp.getUnit() != null) { - String unit = StringUtils.replace(dp.getUnit(), "100%", "%"); - return StringUtils.replace(unit, "%", "%%"); + return dp.getUnit().replace("100%", "%").replace("%", "%%"); } return null; } @@ -182,7 +188,7 @@ public static String getStatePattern(HmDatapoint dp) { * Returns the label string for the given Datapoint. */ public static String getLabel(HmDatapoint dp) { - return WordUtils.capitalizeFully(StringUtils.replace(dp.getName(), "_", " ")); + return MiscUtils.capitalize(dp.getName().replace("_", " ")); } /** @@ -198,7 +204,7 @@ public static String getParameterName(HmDatapoint dp) { public static String getDescription(String... keys) { StringBuilder sb = new StringBuilder(); for (int startIdx = 0; startIdx < keys.length; startIdx++) { - String key = StringUtils.join(keys, "|", startIdx, keys.length); + String key = String.join("|", Arrays.copyOfRange(keys, startIdx, keys.length)); if (key.endsWith("|")) { key = key.substring(0, key.length() - 1); } @@ -209,7 +215,7 @@ public static String getDescription(String... keys) { sb.append(key).append(", "); } if (logger.isTraceEnabled()) { - logger.trace("Description not found for: {}", StringUtils.substring(sb.toString(), 0, -2)); + logger.trace("Description not found for: {}", sb.toString().substring(0, sb.length() - 2)); } return null; } @@ -224,9 +230,8 @@ public static String getDeviceName(HmDevice device) { String deviceDescription = null; boolean isTeam = device.getType().endsWith("-Team"); - String type = isTeam ? StringUtils.remove(device.getType(), "-Team") : device.getType(); + String type = isTeam ? device.getType().replace("-Team", "") : device.getType(); deviceDescription = getDescription(type); - if (deviceDescription != null && isTeam) { deviceDescription += " Team"; } @@ -276,7 +281,10 @@ public static BigDecimal createBigDecimal(Number number) { */ public static String getItemType(HmDatapoint dp) { String dpName = dp.getName(); - String channelType = StringUtils.defaultString(dp.getChannel().getType()); + String channelType = dp.getChannel().getType(); + if (channelType == null) { + channelType = ""; + } if (dp.isBooleanType()) { if (((dpName.equals(DATAPOINT_NAME_STATE) || dpName.equals(VIRTUAL_DATAPOINT_NAME_STATE_CONTACT)) @@ -359,7 +367,10 @@ public static boolean isRollerShutter(HmDatapoint dp) { */ public static String getCategory(HmDatapoint dp, String itemType) { String dpName = dp.getName(); - String channelType = StringUtils.defaultString(dp.getChannel().getType()); + String channelType = dp.getChannel().getType(); + if (channelType == null) { + channelType = ""; + } if (dpName.equals(DATAPOINT_NAME_BATTERY_TYPE) || dpName.equals(DATAPOINT_NAME_LOWBAT) || dpName.equals(DATAPOINT_NAME_LOWBAT_IP)) { diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/UidUtils.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/UidUtils.java index c2aa4d161f4cd..b04f28687cde1 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/UidUtils.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/UidUtils.java @@ -14,7 +14,6 @@ import static org.openhab.binding.homematic.internal.HomematicBindingConstants.BINDING_ID; -import org.apache.commons.lang.math.NumberUtils; import org.openhab.binding.homematic.internal.model.HmChannel; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmDatapointInfo; @@ -83,8 +82,15 @@ public static ChannelUID generateChannelUID(HmDatapoint dp, ThingUID thingUID) { * Generates the HmDatapointInfo for the given thing and channelUID. */ public static HmDatapointInfo createHmDatapointInfo(ChannelUID channelUID) { - return new HmDatapointInfo(channelUID.getThingUID().getId(), HmParamsetType.VALUES, - NumberUtils.toInt(channelUID.getGroupId()), channelUID.getIdWithoutGroup()); + int value; + try { + String groupID = channelUID.getGroupId(); + value = groupID == null ? 0 : Integer.parseInt(groupID); + } catch (NumberFormatException e) { + value = 0; + } + return new HmDatapointInfo(channelUID.getThingUID().getId(), HmParamsetType.VALUES, value, + channelUID.getIdWithoutGroup()); } /** diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/generator/CcuMetadataExtractor.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/generator/CcuMetadataExtractor.java index e232c8d32192a..0dc6f526521e9 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/generator/CcuMetadataExtractor.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/generator/CcuMetadataExtractor.java @@ -25,9 +25,6 @@ import java.util.Map.Entry; import java.util.TreeMap; -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; - /** * The CcuMetadataExtractor loads some JavaScript files from the CCU and generates the device and datapoint * descriptions into the file generated-descriptions.properties. @@ -122,7 +119,7 @@ private void generate() throws IOException { */ private Map loadJsonLangDescriptionFile(String url, String lang) throws IOException { final Map descriptions = new TreeMap<>(); - String descriptionUrl = StringUtils.replace(url, "{LANGUAGE}", lang); + String descriptionUrl = url.replace("{LANGUAGE}", lang); String startLine = " \"" + lang + "\" : {"; String endLine = " },"; @@ -132,7 +129,7 @@ private Map loadJsonLangDescriptionFile(String url, String lang) public void line(String line) { String[] entry = handleStringTable(line); if (entry != null) { - descriptions.put(StringUtils.trim(entry[0]), unescape(StringUtils.trim(entry[1]))); + descriptions.put(entry[0].trim(), unescape(entry[1].trim())); } } }; @@ -150,20 +147,24 @@ private Map loadDeviceKeys() throws IOException { @Override public void line(String line) { if (line.startsWith("elvST['")) { - line = StringUtils.remove(line, "elvST['"); - line = StringUtils.replace(line, "'] = '", "="); - line = StringUtils.remove(line, "';"); - line = StringUtils.remove(line, "$"); - line = StringUtils.remove(line, "{"); - line = StringUtils.remove(line, "}"); - - int count = StringUtils.countMatches(line, "="); + line = line.replace("elvST['", ""); + line = line.replace("'] = '", "="); + line = line.replace("';", ""); + line = line.replace("$", ""); + line = line.replace("{", ""); + line = line.replace("}", ""); + + int count = 0; + for (int i = 0; i < line.length(); i++) { + if (line.charAt(i) == '=') { + count++; + } + } if (count > 1) { - line = StringUtils.replace(line, "=", "|", 1); + line = line.replaceFirst("=", "|"); } - - String[] split = StringUtils.split(line, "=", 2); - deviceKeys.put(StringUtils.trim(split[0]), StringUtils.trim(split[1])); + String[] split = line.split("=", 2); + deviceKeys.put(split[0].trim(), split[1].trim()); } } }; @@ -174,11 +175,11 @@ public void line(String line) { * Splits a JSON JavaScript entry. */ private String[] handleStringTable(String line) { - line = StringUtils.remove(line, " \""); - line = StringUtils.remove(line, "\","); - line = StringUtils.remove(line, "\""); + line = line.replace(" \"", ""); + line = line.replace("\",", ""); + line = line.replace("\"", ""); - String[] splitted = StringUtils.split(line, ":", 2); + String[] splitted = line.split(":", 2); return splitted.length != 2 ? null : splitted; } @@ -186,16 +187,21 @@ private String[] handleStringTable(String line) { * Transforms a string for a Java property file. */ private String unescape(String str) { - str = StringUtils.replace(str, "%FC", "ü"); - str = StringUtils.replace(str, "%DC", "Ü"); - str = StringUtils.replace(str, "%E4", "ä"); - str = StringUtils.replace(str, "%C4", "Ä"); - str = StringUtils.replace(str, "%F6", "ö"); - str = StringUtils.replace(str, "%D6", "Ö"); - str = StringUtils.replace(str, "%DF", "ß"); - str = StringUtils.remove(str, " "); - str = StringUtils.replace(str, "
", " "); - str = StringEscapeUtils.unescapeHtml(str); + str = str.replace("%FC", "ü"); + str = str.replace("%DC", "Ü"); + str = str.replace("%E4", "ä"); + str = str.replace("%C4", "Ä"); + str = str.replace("%F6", "ö"); + str = str.replace("%D6", "Ö"); + str = str.replace("%DF", "ß"); + str = str.replace(" ", ""); + str = str.replace("
", " "); + str = str.replace("ü", "ü"); + str = str.replace("ä", "ä"); + str = str.replace("ö", "ö"); + str = str.replace("Ü", "Ü"); + str = str.replace("Ä", "Ä"); + str = str.replace("Ö", "Ö"); return str; } @@ -222,7 +228,7 @@ public UrlLoader(String url, String startLine, String endLine) throws IOExceptio includeLine = false; } } - if ((includeLine == null || includeLine) && StringUtils.isNotBlank(line)) { + if ((includeLine == null || includeLine) && !line.isBlank()) { line(line); } }