]> git.basschouten.com Git - openhab-addons.git/commitdiff
[jeelink] Fixed wrong TX22 rain value (#14224)
authorlsiepel <leosiepel@gmail.com>
Sat, 21 Jan 2023 08:50:09 +0000 (09:50 +0100)
committerGitHub <noreply@github.com>
Sat, 21 Jan 2023 08:50:09 +0000 (09:50 +0100)
* Divide instead of multiply
* Remove apache.commons

Signed-off-by: lsiepel <leosiepel@gmail.com>
bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LaCrosseTemperatureSensorHandler.java
bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/LgwSensorHandler.java
bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/lacrosse/Tx22ReadingConverter.java
bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/util/StringUtils.java [new file with mode: 0644]

index d4b6cfe37208b47f9b1b581fd00ad0525775ba6f..91d54179f4b6e5fa4c3c6e1d5e448ee39edbea6b 100644 (file)
@@ -21,12 +21,12 @@ import java.util.HashMap;
 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;
index e059c80a0af226e686abf444f00ba8368ee3632c..c6422ed6c8e405e81608c72a7cb0919f8c9945ce 100644 (file)
@@ -18,10 +18,10 @@ import static org.openhab.core.library.unit.MetricPrefix.*;
 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;
index 5d464865af020edc522e52e0d21448f18410e439..dff632e463841f12db3a1be2f6ce11809bc6735d 100644 (file)
@@ -83,7 +83,7 @@ public class Tx22ReadingConverter implements JeeLinkReadingConverter<Tx22Reading
                 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;
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 (file)
index 0000000..d5d9333
--- /dev/null
@@ -0,0 +1,48 @@
+/**
+ * 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;
+
+/**
+ * Utility class for strings
+ *
+ * @author Leo Siepel - Initial contribution
+ */
+@NonNullByDefault
+public final class StringUtils {
+
+    /**
+     * <p>
+     * Capitalizes a String changing the first character to title case.
+     * No other characters are changed.
+     * </p>
+     *
+     * <pre>
+     * StringUtils.capitalize(null)  = null
+     * StringUtils.capitalize("")    = ""
+     * StringUtils.capitalize("cat") = "Cat"
+     * StringUtils.capitalize("cAt") = "CAt"
+     * StringUtils.capitalize("'cat'") = "'cat'"
+     * </pre>
+     *
+     * @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);
+    }
+}