]> git.basschouten.com Git - openhab-addons.git/blob
3630854fa9b37d4896e65d114dba23c7b8d634ab
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.dsmr.internal.meter;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
22 import org.openhab.binding.dsmr.internal.device.cosem.CosemObject;
23
24 /**
25  * Test class for {@link DSMRMeter}.
26  *
27  * @author Hilbrand Bouwkamp - Initial contribution
28  */
29 @NonNullByDefault
30 public class DSMRMeterTest {
31
32     /**
33      * Test if method {@link DSMRMeter#filterMeterValues(List)} correctly filters values.
34      */
35     @Test
36     public void testFilterMeterValues() {
37         final List<CosemObject> cosemObjects = TelegramReaderUtil.readTelegram("dsmr_50").getCosemObjects();
38
39         assertMeterValues(cosemObjects, DSMRMeterType.DEVICE_V5, DSMRMeterConstants.UNKNOWN_CHANNEL, 3);
40         assertMeterValues(cosemObjects, DSMRMeterType.ELECTRICITY_V5_0, 0, 29);
41         assertMeterValues(cosemObjects, DSMRMeterType.M3_V5_0, 1, 3);
42     }
43
44     private void assertMeterValues(final List<CosemObject> cosemObjects, final DSMRMeterType type, final int channel,
45             final int expected) {
46         final DSMRMeterDescriptor descriptor = new DSMRMeterDescriptor(type, channel);
47         final DSMRMeter meter = new DSMRMeter(descriptor);
48         final List<CosemObject> filterMeterValues = meter.filterMeterValues(cosemObjects, channel);
49
50         assertEquals(expected, filterMeterValues.size(), "Filter should return all required objects");
51     }
52 }