Skip to content

Commit

Permalink
Only restore dynamic attribute state from the node database, except for
Browse files Browse the repository at this point in the history
manufacturer-specific attributes

This resolves zsmartsystems#989 and zsmartsystems#236.

Signed-off-by: Henning Sudbrock <[email protected]>
  • Loading branch information
hsudbrock committed Mar 13, 2020
1 parent 9492413 commit 2a42d84
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,17 @@ public void setDao(ZclCluster cluster, ZclAttributeDao dao) {
reportingTimeout = dao.getReportingTimeout();
manufacturerCode = dao.getManufacturerCode();
}

/**
* Sets the dynamic state of the attribute from a {@link ZclAttributeDao} which has been restored from a persisted state.
*
* @param dao the {@link ZclAttributeDao} from which to restore the dynamic state
*/
public void setDynamicStateFromDao(ZclAttributeDao dao) {
implemented = dao.isImplemented();
lastValue = dao.getLastValue();
lastReportTime = dao.getLastReportTime();
}

/**
* Returns a Data Acquisition Object for this attribute. This is a clean class recording the state of the primary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1598,20 +1598,21 @@ public void setDao(ZclClusterDao dao) {
supportedCommandsGenerated.addAll(dao.getSupportedCommandsGenerated());
supportedCommandsReceived.addAll(dao.getSupportedCommandsReceived());

Map<Integer, ZclAttribute> daoZclAttributes = new HashMap<>();
Map<Integer, ZclAttribute> attributes = isClient ? clientAttributes : serverAttributes;

for (ZclAttributeDao daoAttribute : dao.getAttributes().values()) {
// Normalize the data to protect against the users serialisation system restoring incorrect data classes
daoAttribute
.setLastValue(normalizer.normalizeZclData(daoAttribute.getDataType(), daoAttribute.getLastValue()));
ZclAttribute attribute = new ZclAttribute();
attribute.setDao(this, daoAttribute);
daoZclAttributes.put(daoAttribute.getId(), attribute);
}

if (isClient) {
clientAttributes = daoZclAttributes;
} else {
serverAttributes = daoZclAttributes;

ZclAttribute attribute = attributes.get(daoAttribute.getId());
if (attribute == null || daoAttribute.getManufacturerCode() != null) {
attribute = new ZclAttribute();
attribute.setDao(this, daoAttribute);
attributes.put(daoAttribute.getId(), attribute);
} else {
attribute.setDynamicStateFromDao(daoAttribute);
}
}
}

Expand Down

0 comments on commit 2a42d84

Please sign in to comment.