Skip to content

Commit

Permalink
[dsmr] Add support for Austrian meters, Fix for channel id detection (o…
Browse files Browse the repository at this point in the history
…penhab#11458)

* Fix fix for channel id detection, Added missing channels to emucs electra

- M-bus channels are dynamic and present in the obis id.
The binding had most channel types fixed because most of the time these channels are the same.
However the device identifier is the same for multiple devices.
But the binding only registered only one and while the channel id was derived from this obis data.
For detected meters this resulted in the channel id to be the same if there are multiple devices.
This change looks at the channel id to assign it to the found device.
This is a bit tricky because the general device has no channel and has channels that have different id's.
So the binding needs to cover that case.

This change also adds some optional channels to the emucs electra meter.

Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>

* [dsmr] Add support for Austrian meters

Improved the work done in pr openhab#11193

Also-by: Thomas <thomas@knaller.info>
Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>

* [dsmr] Added Null handling annotations.
  • Loading branch information
Hilbrand authored Oct 30, 2021
1 parent c8a7861 commit fdd55a1
Show file tree
Hide file tree
Showing 30 changed files with 655 additions and 465 deletions.
283 changes: 146 additions & 137 deletions bundles/org.openhab.binding.dsmr/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
*/
package org.openhab.binding.dsmr.internal.device.connector;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* Error events from a connector.
*
* @author M. Volaart - Initial contribution
* @author Hilbrand Bouwkamp - Reduced number of event to only errors
*/
@NonNullByDefault
public enum DSMRConnectorErrorEvent {
DONT_EXISTS,
IN_USE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,14 @@ public void parseCosemValues(String cosemValueString) throws ParseException {

int cosemValueItr = 0;
while (cosemValueMatcher.find()) {
Entry<String, CosemValueDescriptor<?>> valueDescriptorEntry = type.getDescriptor(cosemValueItr);
State cosemValue = valueDescriptorEntry.getValue().getStateValue(cosemValueMatcher.group(2));

if (cosemValue != null) {
if (!cosemValues.containsKey(valueDescriptorEntry.getKey())) {
cosemValues.put(valueDescriptorEntry.getKey(), cosemValue);
} else {
logger.warn("Value for descriptor {} already exists, dropping value {}", valueDescriptorEntry,
cosemValue);
}
final Entry<String, CosemValueDescriptor<?>> valueDescriptorEntry = type.getDescriptor(cosemValueItr);
final State cosemValue = valueDescriptorEntry.getValue().getStateValue(cosemValueMatcher.group(2));

if (!cosemValues.containsKey(valueDescriptorEntry.getKey())) {
cosemValues.put(valueDescriptorEntry.getKey(), cosemValue);
} else {
logger.warn("Value for descriptor {} already exists, dropping value {}", valueDescriptorEntry,
cosemValue);
}
cosemValueItr++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ public class CosemObjectFactory {
*/
private final Map<OBISIdentifier, List<CosemObjectType>> obisLookupTableMultipleFixed = new HashMap<>();

/**
* Lookup cache for dynamic OBIS Identifiers
*/
private final Map<OBISIdentifier, CosemObjectType> obisLookupTableDynamic = new HashMap<>();

/**
* Lookup cache for wild card Cosem Object types
*/
private final List<CosemObjectType> obisWildcardCosemTypeList = new ArrayList<>();

/**
* Creates a new CosemObjectFactory
*/
Expand All @@ -64,17 +54,15 @@ public CosemObjectFactory() {
* (i.e. groupA == null || groupB == null || groupC == null). This lookuptable will be filled
* dynamically with unique wildcard OBISIdentifiers when values are received and matches a particular real
* device (if the device is changed, this lookupTable must be cleared by removing the corresponding DSMRDevice
* Thing from the configuration.
* Thing from the configuration.)
* - obisWildCardCosemTypeList. This is the list of all wild card Cosem Object types. Multiple Cosem Object
* Types can have the same wild card OBISIdentifer.
*
* To facilitate autodiscovery the list has all supported CosemObjectTypes. To improve performance once the
* correct OBISIdentifier is discovered for a certain OBISMsgType this is added to the obisLookupTableDynamic.
*/
for (CosemObjectType msgType : CosemObjectType.values()) {
if (msgType.obisId.reducedOBISIdentifierIsWildCard()) {
obisWildcardCosemTypeList.add(msgType);
} else if (msgType.obisId.isConflict()) {
if (msgType.obisId.isConflict()) {
obisLookupTableMultipleFixed.computeIfAbsent(msgType.obisId, r -> new ArrayList<>()).add(msgType);
} else {
obisLookupTableFixed.put(msgType.obisId, msgType);
Expand Down Expand Up @@ -123,29 +111,11 @@ public CosemObjectFactory() {
}
}

objectType = obisLookupTableDynamic.get(reducedObisId);
if (objectType != null) {
logger.trace("Found obisId {} in the dynamic lookup table", reducedObisId);
return getCosemObjectInternal(objectType, obisId, cosemStringValues);
}

objectType = obisLookupTableFixed.get(reducedObisIdGroupE);
if (objectType != null) {
return getCosemObjectInternal(objectType, obisId, cosemStringValues);
}

for (CosemObjectType obisMsgType : obisWildcardCosemTypeList) {
if (obisMsgType.obisId.equalsWildCard(reducedObisId)) {
CosemObject cosemObject = getCosemObjectInternal(obisMsgType, obisId, cosemStringValues);
if (cosemObject != null) {
logger.trace("Searched reducedObisId {} in the wild card type list, result: {}", reducedObisId,
cosemObject);
obisLookupTableDynamic.put(reducedObisId, obisMsgType);
return cosemObject;
}
}
}

logger.debug("Received unknown Cosem Object(OBIS id: {})", obisId);

return null;
Expand Down
Loading

0 comments on commit fdd55a1

Please sign in to comment.