Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description>eBUS core library - This library handles the communication with heating engineering via the BUS specification. This protocol is used by many heating manufacturers in Europe.</description>
<groupId>de.cs-dev.ebus</groupId>
<artifactId>ebus-core</artifactId>
<version>1.1.14</version>
<version>1.2.0</version>
<url>https://github.com/csowada/ebus</url>
<packaging>bundle</packaging>

Expand Down Expand Up @@ -307,21 +307,14 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.16</version>
<version>1.5.20</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<version>1.7.36</version>
<scope>provided</scope>
</dependency>

Expand All @@ -336,15 +329,15 @@
<dependency>
<groupId>com.fazecast</groupId>
<artifactId>jSerialComm</artifactId>
<version>2.11.0</version>
<version>2.11.2</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.1</version>
<version>2.10.1</version>
<scope>provided</scope>
</dependency>

Expand Down
246 changes: 178 additions & 68 deletions src/main/java/de/csdev/ebus/cfg/std/EBusConfigurationReader.java

Large diffs are not rendered by default.

68 changes: 42 additions & 26 deletions src/main/java/de/csdev/ebus/cfg/std/EBusValueJsonDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import java.util.List;
import java.util.Map.Entry;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.jdt.annotation.Nullable;

import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
Expand All @@ -37,27 +36,14 @@
*/
public class EBusValueJsonDeserializer implements JsonDeserializer<List<EBusValueDTO>> {

@SuppressWarnings("unused")
private final Logger logger = LoggerFactory.getLogger(EBusValueJsonDeserializer.class);

@Override
public List<EBusValueDTO> deserialize(JsonElement jElement, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {

JsonArray asJsonArray = jElement.getAsJsonArray();
ArrayList<EBusValueDTO> result = new ArrayList<>();

ArrayList<String> fields = new ArrayList<>();
for (Field field : EBusValueDTO.class.getDeclaredFields()) {

SerializedName annotation = field.getAnnotation(SerializedName.class);
if (annotation != null) {
fields.add(annotation.value());

} else {
fields.add(field.getName());
}
}
final List<String> fields = getFields();

for (JsonElement jsonElement : asJsonArray) {
JsonObject jObject = jsonElement.getAsJsonObject();
Expand All @@ -68,16 +54,7 @@ public List<EBusValueDTO> deserialize(JsonElement jElement, Type typeOfT, JsonDe

if (entry.getValue().isJsonPrimitive()) {
JsonPrimitive primitive = (JsonPrimitive) entry.getValue();

if (primitive.isNumber()) {
valueDTO.setProperty(entry.getKey(), primitive.getAsBigDecimal());

} else if (primitive.isBoolean()) {
valueDTO.setProperty(entry.getKey(), primitive.getAsBoolean());

} else if (primitive.isString()) {
valueDTO.setProperty(entry.getKey(), primitive.getAsString());
}
setPrimitiveProperty(valueDTO, entry, primitive);

} else {
valueDTO.setProperty(entry.getKey(), entry.getValue().getAsString());
Expand All @@ -93,4 +70,43 @@ public List<EBusValueDTO> deserialize(JsonElement jElement, Type typeOfT, JsonDe
return result;
}

/**
* Set a property on the given valueDTO based on the type of the primitive
*
* @param valueDTO
* @param entry
* @param primitive
*/
private void setPrimitiveProperty(EBusValueDTO valueDTO, Entry<String, JsonElement> entry, JsonPrimitive primitive) {
if (primitive.isNumber()) {
valueDTO.setProperty(entry.getKey(), primitive.getAsBigDecimal());

} else if (primitive.isBoolean()) {
valueDTO.setProperty(entry.getKey(), primitive.getAsBoolean());

} else if (primitive.isString()) {
valueDTO.setProperty(entry.getKey(), primitive.getAsString());
}
}

/**
* @return the list of field names of EBusValueDTO
*/
@SuppressWarnings("unused")
private ArrayList<String> getFields() {
ArrayList<String> fields = new ArrayList<>();
for (Field field : EBusValueDTO.class.getDeclaredFields()) {


@Nullable SerializedName annotation = field.getAnnotation(SerializedName.class);
if (annotation != null) {
fields.add(annotation.value());

} else {
fields.add(field.getName());
}
}
return fields;
}

}
8 changes: 4 additions & 4 deletions src/main/java/de/csdev/ebus/command/EBusCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,21 @@ public void setLabel(@Nullable String label) {
}

public void setParentCollection(IEBusCommandCollection parentCollection) {
Objects.requireNonNull(parentCollection, "parentCollection");
Objects.requireNonNull(parentCollection, "parentCollection must not be null");
this.parentCollection = parentCollection;
}

public void setProperties(Map<String, Object> properties) {
Objects.requireNonNull(properties, "properties");
Objects.requireNonNull(properties, "properties must not be null");
HashMap<String, Object> props = new HashMap<>();
props.putAll(properties);
this.properties = props;
}

public void setProperty(String key, String value) {

Objects.requireNonNull(key, "key");
Objects.requireNonNull(value, "value");
Objects.requireNonNull(key, "key must not be null");
Objects.requireNonNull(value, "value must not be null");

this.properties = CollectionUtils.newMapIfNull(this.properties);

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/de/csdev/ebus/command/EBusCommandRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.Map;
import java.util.Objects;

import org.apache.commons.lang3.ObjectUtils;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.slf4j.Logger;
Expand All @@ -33,6 +32,7 @@
import de.csdev.ebus.core.EBusConsts;
import de.csdev.ebus.utils.CollectionUtils;
import de.csdev.ebus.utils.EBusUtils;
import de.csdev.ebus.utils.ObjectUtil;

/**
* @author Christian Sowada - Initial contribution
Expand Down Expand Up @@ -147,7 +147,7 @@ public void addCommandCollection(IEBusCommandCollection collection) {
ByteBuffer buffer = ByteBuffer.wrap(data);

if (buffer == null) {
return CollectionUtils.emptyList();
return CollectionUtils.emptyList();
}

return find(buffer);
Expand Down Expand Up @@ -255,9 +255,9 @@ public EBusTypeRegistry getTypeRegistry() {
@SuppressWarnings("java:S3776")
public boolean matchesCommand(@NonNull IEBusCommandMethod command, @NonNull ByteBuffer data) {

Byte sourceAddress = ObjectUtils.defaultIfNull(command.getSourceAddress(), Byte.valueOf((byte) 0x00));
Byte sourceAddress = ObjectUtil.defaultIfNull(command.getSourceAddress(), Byte.valueOf((byte) 0x00));

Byte targetAddress = ObjectUtils.defaultIfNull(command.getDestinationAddress(),
Byte targetAddress = ObjectUtil.defaultIfNull(command.getDestinationAddress(),
Byte.valueOf((byte) 0x00));

// fast check - is this the right telegram type?
Expand Down
Loading