2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.dsmr.internal.meter;
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.stream.Collectors;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.dsmr.internal.device.cosem.CosemObject;
21 import org.openhab.binding.dsmr.internal.device.cosem.CosemObjectType;
22 import org.openhab.binding.dsmr.internal.device.cosem.OBISIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * DSMR Meter represents a meter for this binding.
29 * A physical meter is a certain {@link DSMRMeterType} on a M-Bus channel. This is the {@link DSMRMeterDescriptor}
30 * and is a private member of the {@link DSMRMeter}.
32 * @author M. Volaart - Initial contribution
33 * @author Hilbrand Bouwkamp - Refactored class, removed actual handling and moved to handler class
36 public class DSMRMeter {
37 private final Logger logger = LoggerFactory.getLogger(DSMRMeter.class);
40 * Meter identification.
42 private final DSMRMeterDescriptor meterDescriptor;
45 * List of supported message identifiers for this meter
47 private List<OBISIdentifier> supportedIdentifiers = new ArrayList<>();
50 * Creates a new DSMRMeter
52 * @param meterDescriptor {@link DSMRMeterDescriptor} containing the description of the new meter
54 public DSMRMeter(DSMRMeterDescriptor meterDescriptor) {
55 this.meterDescriptor = meterDescriptor;
57 for (CosemObjectType msgType : meterDescriptor.getMeterType().supportedCosemObjects) {
58 OBISIdentifier obisId = msgType.obisId;
59 if (msgType.obisId.getChannel() == null) {
60 supportedIdentifiers.add(new OBISIdentifier(obisId.getGroupA(), obisId.getGroupC(), obisId.getGroupD(),
63 supportedIdentifiers.add(msgType.obisId);
69 * Returns a list of Cosem Objects this meter will handle and removed them from the passed {@link CosemObject} list.
71 * @param cosemObjects list of CosemObject that must be processed and where the objects of this meter are removed
72 * @return List of CosemObject that this meter can process
74 public List<CosemObject> filterMeterValues(List<CosemObject> cosemObjects, int channel) {
75 logger.trace("supported identifiers: {}, searching for objects {}", supportedIdentifiers, cosemObjects);
76 return cosemObjects.stream()
77 .filter(cosemObject -> (DSMRMeterConstants.UNKNOWN_CHANNEL == channel
78 || cosemObject.getObisIdentifier().getChannel() == channel)
79 && supportedIdentifiers.contains(cosemObject.getObisIdentifier().getReducedOBISIdentifier()))
80 .collect(Collectors.toList());
84 * @return Returns the {@link DSMRMeterDescriptor} this object is configured with
86 public DSMRMeterDescriptor getMeterDescriptor() {
87 return meterDescriptor;
91 public String toString() {
92 return meterDescriptor.toString();