Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
csowada committed Jan 31, 2021
2 parents ca91a36 + 7f00f29 commit 79c19b7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 62 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.

## Unreleased

## [1.1.5] - 2021-01-31
### Changed
- Removed clone() from DataType objects
- Simplified EbusConfigurationReader methods
### Fixed
- Fix NPE for NestedValues

## [1.1.4] - 2020-12-27
### Changed
- Enhanced the internal ThreadPool from 30 to 60 to prevent issues on startup
Expand Down
2 changes: 1 addition & 1 deletion 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.4</version>
<version>1.1.5</version>
<url>https://github.com/csowada/ebus</url>
<packaging>bundle</packaging>

Expand Down
116 changes: 61 additions & 55 deletions src/main/java/de/csdev/ebus/cfg/std/EBusConfigurationReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public EBusConfigurationReader() {
// add md5 hash
commandCollection.setIdentification(collection.getIdentification());

// parse the template block
parseTemplateConfiguration(collection);
// parse the template list block
parseTemplateListConfiguration(collection);

List<EBusCommandDTO> commands = collection.getCommands();
if (commands != null) {
Expand All @@ -179,7 +179,7 @@ public EBusConfigurationReader() {
return commandCollection;
}

protected void parseTemplateConfiguration(@NonNull EBusCollectionDTO collection)
protected void parseTemplateListConfiguration(@NonNull EBusCollectionDTO collection)
throws EBusConfigurationReaderException {

Objects.requireNonNull(collection, "collection");
Expand All @@ -188,36 +188,42 @@ protected void parseTemplateConfiguration(@NonNull EBusCollectionDTO collection)
List<EBusCommandTemplatesDTO> templateSection = collection.getTemplates();
if (templateSection != null) {
for (EBusCommandTemplatesDTO templates : templateSection) {
List<EBusValueDTO> templateValues = templates.getTemplate();
if (templateValues != null) {
parseTemplateBlockConfiguration(templates.getTemplate(), collection, templates);
}
}
}

Collection<EBusCommandValue> blockList = new ArrayList<>();
protected void parseTemplateBlockConfiguration(@Nullable List<EBusValueDTO> templateValues, @NonNull EBusCollectionDTO collection, @NonNull EBusCommandTemplatesDTO templates)
throws EBusConfigurationReaderException {

for (EBusValueDTO value : templateValues) {
if (value != null) {
Collection<@NonNull EBusCommandValue> pv = parseValueConfiguration(value, null, null, null);
if (templateValues == null) {
return;
}

if (pv != null && !pv.isEmpty()) {
blockList.addAll(pv);
Collection<EBusCommandValue> blockList = new ArrayList<>();

// global id
String id = collection.getId() + "." + templates.getName() + "." + value.getName();
logger.trace("Add template with global id {} to registry ...", id);
templateValueRegistry.put(id, pv);
}
}
}
for (EBusValueDTO value : templateValues) {
if (value != null) {
Collection<@NonNull EBusCommandValue> pv = parseValueConfiguration(value, null, null, null);

if (!blockList.isEmpty()) {
String id = collection.getId() + "." + templates.getName();
if (!pv.isEmpty()) {
blockList.addAll(pv);

// global id
logger.trace("Add template block with global id {} to registry ...", id);
templateBlockRegistry.put(id, blockList);
}
// global id
String id = collection.getId() + "." + templates.getName() + "." + value.getName();
logger.trace("Add template with global id {} to registry ...", id);
templateValueRegistry.put(id, pv);
}
}
}

if (!blockList.isEmpty()) {
String id = collection.getId() + "." + templates.getName();

// global id
logger.trace("Add template block with global id {} to registry ...", id);
templateBlockRegistry.put(id, blockList);
}
}

/**
Expand Down Expand Up @@ -255,18 +261,13 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
Byte source = EBusUtils.toByte(commandElement.getSrc());

// read in template block
List<EBusValueDTO> templates = commandElement.getTemplate();
if (templates != null) {
for (EBusValueDTO template : templates) {
if (template != null) {
for (EBusCommandValue templateCfg : parseValueConfiguration(template, null, null, null)) {
if (StringUtils.isEmpty(templateCfg.getName())) {
templateMap.put(templateCfg.getName(), templateCfg);
}

templateList.add(templateCfg);
}
for (EBusValueDTO template : checkedList(commandElement.getTemplate())) {
for (EBusCommandValue templateCfg : parseValueConfiguration(template, null, null, null)) {
if (StringUtils.isEmpty(templateCfg.getName())) {
templateMap.put(templateCfg.getName(), templateCfg);
}

templateList.add(templateCfg);
}
}

Expand Down Expand Up @@ -315,28 +316,16 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
commandMethod.setDestinationAddress(destination);
commandMethod.setSourceAddress(source);

List<EBusValueDTO> master = commandMethodElement.getMaster();
if (master != null) {
for (EBusValueDTO template : master) {
if (template != null) {
for (EBusCommandValue ev : parseValueConfiguration(template, templateMap, templateList,
commandMethod)) {
commandMethod.addMasterValue(ev);
}
for (EBusValueDTO template : checkedList(commandMethodElement.getMaster())) {
for (EBusCommandValue ev : parseValueConfiguration(template, templateMap, templateList, commandMethod)) {
commandMethod.addMasterValue(ev);
}
}
}

List<EBusValueDTO> slave = commandMethodElement.getSlave();
if (slave != null) {
for (EBusValueDTO template : slave) {
if (template != null) {
for (EBusCommandValue ev : parseValueConfiguration(template, templateMap, templateList,
commandMethod)) {
commandMethod.addSlaveValue(ev);
}
for (EBusValueDTO template : checkedList(commandMethodElement.getSlave())) {
for (EBusCommandValue ev : parseValueConfiguration(template, templateMap, templateList, commandMethod)) {
commandMethod.addSlaveValue(ev);
}
}
}

// default type is always master-slave if not explicit set or a broadcast
Expand All @@ -363,6 +352,23 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
return cfg;
}

/**
* Helper function to work with a secure non null list
* @param master
* @return
*/
protected @NonNull List<@NonNull EBusValueDTO> checkedList(List<EBusValueDTO> master) {
List<EBusValueDTO> templates = new ArrayList<>();
if (master != null) {
for (EBusValueDTO template : master) {
if (template != null) {
templates.add(template);
}
}
}
return templates;
}

/**
* @param valueDto
* @param templateMap
Expand Down Expand Up @@ -447,7 +453,7 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
} else if (typeStr != null && typeStr.equals("template")) {

String id = (String) valueDto.getProperty("id");
String globalId = collectionId + "." + id;
String globalId = collectionId != null ? collectionId + "." + id : null;
Collection<@NonNull EBusCommandValue> templateCollection = null;

if (StringUtils.isEmpty(id)) {
Expand All @@ -457,7 +463,7 @@ protected EBusCommand parseTelegramConfiguration(@NonNull IEBusCommandCollection
if (templateValueRegistry.containsKey(id)) {
templateCollection = templateValueRegistry.get(id);

} else if (templateValueRegistry.containsKey(globalId)) {
} else if (globalId != null && templateValueRegistry.containsKey(globalId)) {
templateCollection = templateValueRegistry.get(globalId);

} else if (templateMap != null && templateMap.containsKey(id)) {
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/de/csdev/ebus/command/EBusCommandNestedValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ public class EBusCommandNestedValue extends EBusCommandValue implements IEBusNes

@Override
public void setParent(@Nullable EBusCommandMethod parent) {
if (parent != null) {
super.setParent(parent);

Objects.requireNonNull(parent, "parent");

super.setParent(parent);

for (IEBusValue value : list) {
((EBusCommandValue) value).setParent(parent);
for (IEBusValue value : list) {
((EBusCommandValue) value).setParent(parent);
}
}
}

Expand Down

0 comments on commit 79c19b7

Please sign in to comment.