Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[max] Remove org.apache.commons #14413

Merged
merged 14 commits into from
Jun 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import java.util.Set;
import java.util.TreeSet;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.max.internal.Utils;
import org.openhab.binding.max.internal.device.Device;
import org.openhab.binding.max.internal.device.RoomInformation;
import org.openhab.core.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.Base64;
import java.util.List;

import org.apache.commons.lang3.ArrayUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.max.internal.Utils;

Expand Down Expand Up @@ -49,9 +48,13 @@ public void addRoom(String rfAddress) {
@Override
public String getCommandString() {
final int updateForced = forceUpdate ? FORCE_UPDATE : NO_FORCE_UPDATE;
byte[] commandArray = null;
byte[] commandArray = new byte[0];
for (String rfAddress : rfAddresses) {
commandArray = ArrayUtils.addAll(Utils.hexStringToByteArray(rfAddress), commandArray);
byte[] rfAddressArray = Utils.hexStringToByteArray(rfAddress);
byte[] tnmpArray = new byte[rfAddressArray.length + commandArray.length];
System.arraycopy(rfAddressArray, 0, tnmpArray, 0, rfAddressArray.length);
System.arraycopy(commandArray, 0, tnmpArray, rfAddressArray.length, commandArray.length);
commandArray = tnmpArray;
}
String encodedString = Base64.getEncoder().encodeToString(commandArray);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private enum BackupState {
/** maximum queue size that we're allowing */
private static final int MAX_COMMANDS = 50;
private static final int MAX_DUTY_CYCLE = 80;
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HHmm");
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd-HHmm");

private final Logger logger = LoggerFactory.getLogger(MaxCubeBridgeHandler.class);
private final List<Device> devices = new ArrayList<>();
Expand Down Expand Up @@ -1025,7 +1025,7 @@ public boolean hasExcessDutyCycle() {
public void backup() {
this.backup = BackupState.REQUESTED;
this.backupUtil = new MaxBackupUtils(
new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().format(formatter));
new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().format(FORMATTER));
socketClose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -536,30 +536,30 @@ public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
*/
private void setDeviceConfiguration(Device device) {
try {
boolean config_changed = false;
boolean configChanged = false;
logger.debug("MAX! {} {} configuration update", device.getType(), device.getSerialNumber());
Configuration configuration = editConfiguration();
if (!device.getRoomName().equalsIgnoreCase((String) getConfig().get(PROPERTY_ROOMNAME))) {
configuration.put(PROPERTY_ROOMNAME, device.getRoomName());
config_changed = true;
configChanged = true;
}
if (getConfig().get(PROPERTY_ROOMID) == null || new BigDecimal(device.getRoomId())
.compareTo((BigDecimal) getConfig().get(PROPERTY_ROOMID)) != 0) {
configuration.put(PROPERTY_ROOMID, new BigDecimal(device.getRoomId()));
config_changed = true;
configChanged = true;
}
if (!device.getName().equalsIgnoreCase((String) getConfig().get(PROPERTY_DEVICENAME))) {
configuration.put(PROPERTY_DEVICENAME, device.getName());
config_changed = true;
configChanged = true;
}
if (!device.getRFAddress().equalsIgnoreCase((String) getConfig().get(PROPERTY_RFADDRESS))) {
configuration.put(PROPERTY_RFADDRESS, device.getRFAddress());
config_changed = true;
configChanged = true;
}
for (Map.Entry<String, Object> entry : device.getProperties().entrySet()) {
configuration.put(entry.getKey(), entry.getValue());
}
if (config_changed) {
if (configChanged) {
updateConfiguration(configuration);
logger.debug("Config updated: {}", configuration.getProperties());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.max.internal.Utils;
import org.openhab.binding.max.internal.device.DeviceType;
import org.openhab.core.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -109,11 +109,7 @@ public CMessage(String raw) {

private String getSerialNumber(byte[] bytes) {
byte[] sn = new byte[10];

for (int i = 0; i < 10; i++) {
sn[i] = bytes[i + 8];
}

System.arraycopy(bytes, 8, sn, 0, sn.length);
return new String(sn, StandardCharsets.UTF_8);
}

Expand All @@ -124,10 +120,8 @@ private String parseData(byte[] bytes) {
try {
int dataStart = 18;
byte[] sn = new byte[bytes.length - dataStart];
System.arraycopy(bytes, dataStart, sn, 0, sn.length);

for (int i = 0; i < sn.length; i++) {
sn[i] = bytes[i + dataStart];
}
logger.trace("DataBytes: {}", Utils.getHex(sn));
return new String(sn, StandardCharsets.UTF_8);
} catch (Exception e) {
Expand Down Expand Up @@ -278,7 +272,7 @@ public void debug(Logger logger) {
logger.debug("RoomID: {}", roomId);
for (String key : properties.keySet()) {
if (!key.startsWith("Unknown")) {
String propertyName = String.join(" ", StringUtils.splitByCharacterTypeCamelCase(key));
String propertyName = String.join(" ", StringUtils.splitByCharacterType(key));
logger.debug("{}: {}", propertyName, properties.get(key));
} else {
logger.debug("{}: {}", key, properties.get(key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ public void testSingleM_Message() throws Exception {

@Test
public void testMultilineM_Message() throws Exception {
String line1_part1 = "M:00,02,";
String line1_part2 = "VgIMAQpXb2huemltbWVyCvMrAgtUb2lsZXR0ZSBFRwrenQMOVG9pbGV0dGUgMS4gT0cK3rgECkJhZGV6aW1tZXIK3qoFDFNjaGxhZnppbW1lcgresQYDSmFuD4lCBwlDaHJpc3RpbmEPiTYIBEZsdXIPiT0KEE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MURmVuc3RlciBHYXJ0ZW4gbGlua3MMBA/yI0xFUTA3OTM5MDQVRmVuc3RlciBHYXJ0ZW4gcmVjaHRzDAEPiRpMRVExMDA0NTYwB0hlaXp1bmcMBA/vj0xFUTA3OTQ1NjUPRmVuc3RlciBTdHJhw59lDAQP8CtMRVEwNzk0NDA5BFTDvHIDBAgUa0tFUTAxODcwNjkNRmVuc3RlciBTZWl0ZQUEBzagS0VRMDE4NTkzNhVGZW5zdGVyIFN0cmHDn2UgbGlua3MBBA/wI0xFUTA3OTQ0MTYORmVuc3RlciBLw7xjaGUBAxBV50xFUTA5ODI2NzYOV2FuZHRoZXJtb3N0YXQFAxBW2kxFUTA5ODIzNjgOV2FuZHRoZXJtb3N0YXQEAxBV4kxFUTA5ODI2NzEOV2FuZHRoZXJtb3N0YXQHAxBZWExFUTA5ODE3MjkOV2FuZHRoZXJtb3N0YXQMAxBV6ExFUTA5ODI2NzcOV2FuZHRoZXJtb3N0YXQGAxBV40xFUTA5ODI2NzIOV2FuZHRoZXJtb3N0YXQKBAcxoEtFUTAxODcyMTYLV2FzY2hrw7xjaGUF";
String line1 = line1Part1 + line1Part2;

String line2_part1 = "M:01,02,";
String line2_part2 = "AxBV8ExFUTA5ODI2ODUOV2FuZHRoZXJtb3N0YXQJBA/v50xFUTA3OTQ0NzcNQmFsa29uZmVuc3RlcgkBD4lXTEVRMTAwNDYyMRZIZWl6dW5nIHVudGVybSBGZW5zdGVyCQQP8llMRVEwNzkzODUwDkZlbnN0ZXIgcmVjaHRzCQQP8bxMRVEwNzk0MDA3DUZlbnN0ZXIgbGlua3MJAQ+JOExFUTEwMDQ1OTAOSGVpenVuZyBCYWxrb24JBA/yLExFUTA3OTM4OTUKQmFsa29udMO8cgkED++zTEVRMDc5NDUyOQhGbHVydMO8cgkB";
String line2 = line2_part1 + line2_part2;
String line2Part1 = "M:01,02,";
String line2Part2 = "AxBV8ExFUTA5ODI2ODUOV2FuZHRoZXJtb3N0YXQJBA/v50xFUTA3OTQ0NzcNQmFsa29uZmVuc3RlcgkBD4lXTEVRMTAwNDYyMRZIZWl6dW5nIHVudGVybSBGZW5zdGVyCQQP8llMRVEwNzkzODUwDkZlbnN0ZXIgcmVjaHRzCQQP8bxMRVEwNzk0MDA3DUZlbnN0ZXIgbGlua3MJAQ+JOExFUTEwMDQ1OTAOSGVpenVuZyBCYWxrb24JBA/yLExFUTA3OTM4OTUKQmFsa29udMO8cgkED++zTEVRMDc5NDUyOQhGbHVydMO8cgkB";
String line2 = line2Part1 + line2Part2;

String expectedString = line1 + line2_part2;
String expectedString = line1 + line2Part2;
MMessage expectedMessage = new MMessage(expectedString);

assertFalse(this.processor.addReceivedLine(line1));
Expand Down