import org.openhab.core.io.transport.serial.SerialPort;
import org.openhab.core.io.transport.serial.SerialPortEvent;
import org.openhab.core.io.transport.serial.SerialPortEventListener;
+import org.openhab.core.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
private void parseAndQueue(ByteBuffer readBuffer) {
String response = new String(readBuffer.array(), 0, readBuffer.limit());
- response = response.replace("\r", "").replace("\n", "");
+ response = StringUtils.chomp(response);
Matcher matcher = RESPONSE_PATTERN.matcher(response);
}
}
- public static String upperUnderscoreToLowerCamel(String text) {
- final String delimiter = "_";
- StringBuilder upperCamelBuilder = new StringBuilder(text.length());
- for (String str : text.split(delimiter)) {
- if (upperCamelBuilder.isEmpty() && !str.isEmpty()) {
- upperCamelBuilder.append(str.substring(0, 1).toLowerCase());
- } else if (!str.isEmpty()) {
- upperCamelBuilder.append(str.substring(0, 1).toUpperCase());
- }
- if (str.length() > 1) {
- upperCamelBuilder.append(str.substring(1).toLowerCase());
- }
- }
- return upperCamelBuilder.toString();
- }
-
public static boolean updateProperties(Map<String, String> properties, InformationResponseMessage message) {
boolean update = false;
*/
package org.openhab.binding.plugwise.internal.config;
-import static org.openhab.binding.plugwise.internal.PlugwiseUtils.*;
import static org.openhab.binding.plugwise.internal.config.PlugwiseRelayConfig.PowerStateChanging.COMMAND_SWITCHING;
import java.time.Duration;
+import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.plugwise.internal.PlugwiseUtils;
import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
+import org.openhab.core.util.StringUtils;
/**
* The {@link PlugwiseRelayConfig} class represents the configuration for a Plugwise relay device (Circle, Circle+,
}
private String macAddress = "";
- private String powerStateChanging = upperUnderscoreToLowerCamel(COMMAND_SWITCHING.name());
+ private String powerStateChanging = Objects
+ .requireNonNull(StringUtils.capitalizeByUnderscore(COMMAND_SWITCHING.name()));
private boolean suppliesPower = false;
private int measurementInterval = 60; // minutes
private boolean temporarilyNotInNetwork = false;
}
public PowerStateChanging getPowerStateChanging() {
- return PowerStateChanging.valueOf(lowerCamelToUpperUnderscore(powerStateChanging));
+ return PowerStateChanging.valueOf(PlugwiseUtils.lowerCamelToUpperUnderscore(powerStateChanging));
}
public boolean isSuppliesPower() {
*/
package org.openhab.binding.plugwise.internal.config;
-import static org.openhab.binding.plugwise.internal.PlugwiseUtils.*;
import static org.openhab.binding.plugwise.internal.protocol.field.Sensitivity.MEDIUM;
import java.time.Duration;
+import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.plugwise.internal.PlugwiseUtils;
import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
import org.openhab.binding.plugwise.internal.protocol.field.Sensitivity;
+import org.openhab.core.util.StringUtils;
/**
* The {@link PlugwiseScanConfig} class represents the configuration for a Plugwise Scan.
public class PlugwiseScanConfig {
private String macAddress = "";
- private String sensitivity = upperUnderscoreToLowerCamel(MEDIUM.name());
+ private String sensitivity = Objects.requireNonNull(StringUtils.capitalizeByUnderscore(MEDIUM.name()));
private int switchOffDelay = 5; // minutes
private boolean daylightOverride = false;
private int wakeupInterval = 1440; // minutes (1 day)
}
public Sensitivity getSensitivity() {
- return Sensitivity.valueOf(lowerCamelToUpperUnderscore(sensitivity));
+ return Sensitivity.valueOf(PlugwiseUtils.lowerCamelToUpperUnderscore(sensitivity));
}
public Duration getSwitchOffDelay() {
*/
package org.openhab.binding.plugwise.internal.config;
-import static org.openhab.binding.plugwise.internal.PlugwiseUtils.*;
import static org.openhab.binding.plugwise.internal.protocol.field.BoundaryAction.OFF_BELOW_ON_ABOVE;
import static org.openhab.binding.plugwise.internal.protocol.field.BoundaryType.NONE;
import java.time.Duration;
+import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.plugwise.internal.PlugwiseUtils;
import org.openhab.binding.plugwise.internal.protocol.field.BoundaryAction;
import org.openhab.binding.plugwise.internal.protocol.field.BoundaryType;
import org.openhab.binding.plugwise.internal.protocol.field.Humidity;
import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
import org.openhab.binding.plugwise.internal.protocol.field.Temperature;
+import org.openhab.core.util.StringUtils;
/**
* The {@link PlugwiseScanConfig} class represents the configuration for a Plugwise Sense.
private String macAddress = "";
private int measurementInterval = 15; // minutes
- private String boundaryType = upperUnderscoreToLowerCamel(NONE.name());
- private String boundaryAction = upperUnderscoreToLowerCamel(OFF_BELOW_ON_ABOVE.name());
+ private String boundaryType = Objects.requireNonNull(StringUtils.capitalizeByUnderscore(NONE.name()));
+ private String boundaryAction = Objects
+ .requireNonNull(StringUtils.capitalizeByUnderscore(OFF_BELOW_ON_ABOVE.name()));
private int temperatureBoundaryMin = 15; // degrees Celsius
private int temperatureBoundaryMax = 25; // degrees Celsius
private int humidityBoundaryMin = 45; // relative humidity (RH)
}
public BoundaryType getBoundaryType() {
- return BoundaryType.valueOf(lowerCamelToUpperUnderscore(boundaryType));
+ return BoundaryType.valueOf(PlugwiseUtils.lowerCamelToUpperUnderscore(boundaryType));
}
public BoundaryAction getBoundaryAction() {
- return BoundaryAction.valueOf(lowerCamelToUpperUnderscore(boundaryAction));
+ return BoundaryAction.valueOf(PlugwiseUtils.lowerCamelToUpperUnderscore(boundaryAction));
}
public Temperature getTemperatureBoundaryMin() {
+++ /dev/null
-/**
- * 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.plugwise.internal;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.junit.jupiter.api.Test;
-
-/**
- * The {@link PlugwiseUtilsTest} class tests some static string utility methods
- *
- * @author Leo Siepel - Initial contribution
- */
-@NonNullByDefault
-public class PlugwiseUtilsTest {
-
- @Test
- public void upperUnderscoreToLowerCamelBaseTest() {
- assertEquals("nodelimiterpresent", PlugwiseUtils.upperUnderscoreToLowerCamel("NoDelimiterPresent"));
- assertEquals("delimiterIsPresent", PlugwiseUtils.upperUnderscoreToLowerCamel("DeliMiter_iS_PreSent"));
- assertEquals("doubleDelimitersDouble", PlugwiseUtils.upperUnderscoreToLowerCamel("DOUBLE__DELIMITERS__DOUBLE"));
- assertEquals("helloWorld", PlugwiseUtils.upperUnderscoreToLowerCamel("HELLO_WORLD"));
- assertEquals("", PlugwiseUtils.upperUnderscoreToLowerCamel(""));
- assertEquals("", PlugwiseUtils.upperUnderscoreToLowerCamel("_"));
- }
-}