From 049e5fb96e1219836e8a7568e667b3ae39284e0e Mon Sep 17 00:00:00 2001 From: lsiepel Date: Sat, 14 Jan 2023 12:59:44 +0100 Subject: [PATCH 1/3] Divide instead of multiply Signed-off-by: lsiepel --- .../binding/jeelink/internal/lacrosse/Tx22ReadingConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/Tx22ReadingConverter.java b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/Tx22ReadingConverter.java index 5d464865af020..dff632e463841 100644 --- a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/Tx22ReadingConverter.java +++ b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/Tx22ReadingConverter.java @@ -83,7 +83,7 @@ public Tx22Reading createReading(String inputLine) { Integer humidity = "255".equals(matcher.group(5)) ? null : Integer.parseInt(matcher.group(5)); Integer rain = "255".equals(matcher.group(6)) ? null - : (Integer.parseInt(matcher.group(6)) * 256 + Integer.parseInt(matcher.group(7))) * 2; + : (int) ((Integer.parseInt(matcher.group(6)) * 256 + Integer.parseInt(matcher.group(7))) * 0.5); Float windDirection = "255".equals(matcher.group(8)) ? null : (Integer.parseInt(matcher.group(8)) * 256 + Integer.parseInt(matcher.group(9))) / 10f; From 80cdc838cebf0feabea4845eddc00c26c8c2fa29 Mon Sep 17 00:00:00 2001 From: lsiepel Date: Sat, 14 Jan 2023 13:21:28 +0100 Subject: [PATCH 2/3] Remove apache.commons Signed-off-by: lsiepel --- .../LaCrosseTemperatureSensorHandler.java | 2 +- .../internal/lacrosse/LgwSensorHandler.java | 2 +- .../jeelink/internal/util/StringUtils.java | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java diff --git a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java index d4b6cfe37208b..91d54179f4b6e 100644 --- a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java +++ b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java @@ -21,12 +21,12 @@ import java.util.List; import java.util.Map; -import org.apache.commons.lang3.StringUtils; import org.openhab.binding.jeelink.internal.JeeLinkSensorHandler; import org.openhab.binding.jeelink.internal.ReadingPublisher; import org.openhab.binding.jeelink.internal.RollingAveragePublisher; import org.openhab.binding.jeelink.internal.RollingReadingAverage; import org.openhab.binding.jeelink.internal.config.LaCrosseTemperatureSensorConfig; +import org.openhab.binding.jeelink.internal.util.StringUtils; import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.SIUnits; diff --git a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java index e059c80a0af22..c6422ed6c8e40 100644 --- a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java +++ b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java @@ -18,10 +18,10 @@ import java.math.BigDecimal; import java.math.RoundingMode; -import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.jeelink.internal.JeeLinkSensorHandler; import org.openhab.binding.jeelink.internal.ReadingPublisher; +import org.openhab.binding.jeelink.internal.util.StringUtils; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.SIUnits; import org.openhab.core.library.unit.Units; diff --git a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java new file mode 100644 index 0000000000000..9532aff5a9306 --- /dev/null +++ b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.jeelink.internal.util; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +@NonNullByDefault +public final class StringUtils { + + /** + *

+ * Capitalizes a String changing the first character to title case. + * No other characters are changed. + *

+ * + *
+     * StringUtils.capitalize(null)  = null
+     * StringUtils.capitalize("")    = ""
+     * StringUtils.capitalize("cat") = "Cat"
+     * StringUtils.capitalize("cAt") = "CAt"
+     * StringUtils.capitalize("'cat'") = "'cat'"
+     * 
+ * + * @param val the String to capitalize, may not be null + * @return the capitalized String + */ + public static String capitalize(String val) { + if (val.length() == 0) { + return val; + } + return val.substring(0, 1).toUpperCase() + val.substring(1); + } +} From 014106ae25f172c9c6244560461543d52ae7ffdb Mon Sep 17 00:00:00 2001 From: lsiepel Date: Sun, 15 Jan 2023 18:02:23 +0100 Subject: [PATCH 3/3] add author Signed-off-by: lsiepel --- .../openhab/binding/jeelink/internal/util/StringUtils.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java index 9532aff5a9306..d5d93335f392c 100644 --- a/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java +++ b/bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java @@ -14,6 +14,11 @@ import org.eclipse.jdt.annotation.NonNullByDefault; +/** + * Utility class for strings + * + * @author Leo Siepel - Initial contribution + */ @NonNullByDefault public final class StringUtils {