import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.modbus.internal.AtomicStampedValue;
private final Logger logger = LoggerFactory.getLogger(ModbusPollerThingHandler.class);
private final static List<String> SORTED_READ_FUNCTION_CODES = ModbusBindingConstantsInternal.READ_FUNCTION_CODES
- .keySet().stream().sorted().collect(Collectors.toList());
+ .keySet().stream().sorted().collect(Collectors.toUnmodifiableList());
private @NonNullByDefault({}) ModbusPollerConfiguration config;
private long cacheMillis;
if (!ModbusBindingConstantsInternal.READ_FUNCTION_CODES.containsKey(type)) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
String.format("No function code found for type='%s'. Was expecting one of: %s", type,
- StringUtils.join(SORTED_READ_FUNCTION_CODES, ", ")));
+ String.join(", ", SORTED_READ_FUNCTION_CODES)));
return;
}
functionCode = ModbusBindingConstantsInternal.READ_FUNCTION_CODES.get(type);
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
-import java.util.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
import java.util.concurrent.TimeUnit;
-import org.apache.commons.lang.NotImplementedException;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.modbus.handler.EndpointNotInitializedException;
// Should not happen! This method is not called in case configuration errors and writeType is validated
// already in initialization (validateAndParseWriteParameters).
// We keep this here for future-proofing the code (new writeType values)
- throw new NotImplementedException(String.format(
+ throw new IllegalStateException(String.format(
"writeType does not equal %s or %s and thus configuration is invalid. Should not end up this far with configuration error.",
WRITE_TYPE_COIL, WRITE_TYPE_HOLDING));
}
ModbusReadFunctionCode functionCode = this.functionCode;
boolean readingDiscreteOrCoil = functionCode == ModbusReadFunctionCode.READ_COILS
|| functionCode == ModbusReadFunctionCode.READ_INPUT_DISCRETES;
- boolean readStartMissing = StringUtils.isBlank(config.getReadStart());
- boolean readValueTypeMissing = StringUtils.isBlank(config.getReadValueType());
+ boolean readStartMissing = config.getReadStart() == null || config.getReadStart().isBlank();
+ boolean readValueTypeMissing = config.getReadValueType() == null || config.getReadValueType().isBlank();
if (childOfEndpoint && readRequest == null) {
if (!readStartMissing || !readValueTypeMissing) {
}
private void validateAndParseWriteParameters(ModbusDataConfiguration config) throws ModbusConfigurationException {
- boolean writeTypeMissing = StringUtils.isBlank(config.getWriteType());
- boolean writeStartMissing = StringUtils.isBlank(config.getWriteStart());
- boolean writeValueTypeMissing = StringUtils.isBlank(config.getWriteValueType());
- boolean writeTransformationMissing = StringUtils.isBlank(config.getWriteTransform());
+ boolean writeTypeMissing = config.getWriteType() == null || config.getWriteType().isBlank();
+ boolean writeStartMissing = config.getWriteStart() == null || config.getWriteStart().isBlank();
+ boolean writeValueTypeMissing = config.getWriteValueType() == null || config.getWriteValueType().isBlank();
+ boolean writeTransformationMissing = config.getWriteTransform() == null || config.getWriteTransform().isBlank();
writeTransformation = new Transformation(config.getWriteTransform());
boolean writingCoil = WRITE_TYPE_COIL.equals(config.getWriteType());
writeParametersHavingTransformationOnly = (writeTypeMissing && writeStartMissing && writeValueTypeMissing
localReadTransformation.isIdentityTransform() ? "<identity>" : localReadTransformation);
states.put(channelUID, transformedState);
} else {
- String types = StringUtils.join(acceptedDataTypes.stream().map(cls -> cls.getSimpleName()).toArray(),
- ", ");
+ String types = String.join(", ",
+ acceptedDataTypes.stream().map(cls -> cls.getSimpleName()).toArray(String[]::new));
logger.warn(
"Channel {} will not be updated since transformation was unsuccessful. Channel is expecting the following data types [{}]. Input data: number value {} (value type '{}' taken into account) and bool value {}. Transformation: {}",
channelId, types, numericState, readValueType, boolValue,
import java.util.function.Consumer;
import java.util.function.Function;
-import org.apache.commons.lang.StringUtils;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.openhab.core.io.transport.modbus.endpoint.ModbusTCPSlaveEndpoint;
import org.openhab.core.items.GenericItem;
import org.openhab.core.items.Item;
-import org.openhab.core.library.items.DateTimeItem;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType;
Map<String, ChannelUID> toBeLinked = new HashMap<>();
for (Entry<String, String> entry : CHANNEL_TO_ACCEPTED_TYPE.entrySet()) {
String channelId = entry.getKey();
+ // accepted item type
String channelAcceptedType = entry.getValue();
ChannelUID channelUID = new ChannelUID(thingUID, channelId);
builder = builder.withChannel(ChannelBuilder.create(channelUID, channelAcceptedType).build());
// Create item of correct type and link it to channel
String itemName = getItemName(channelUID);
final GenericItem item;
- if (channelId.startsWith("last") || channelId.equals("datetime")) {
- item = new DateTimeItem(itemName);
- } else {
- item = coreItemFactory.createItem(StringUtils.capitalize(channelId), itemName);
- }
+ item = coreItemFactory.createItem(channelAcceptedType, itemName);
assertThat(String.format("Could not determine correct item type for %s", channelId), item,
is(notNullValue()));
assertNotNull(item);