]> git.basschouten.com Git - openhab-addons.git/blob
7f9d27443a6e3e912c14928d24fc5c3879e7ce4d
[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 import org.openhab.binding.dsmr.internal.device.p1telegram.P1Telegram.TelegramState;
24
25 /**
26  * Test class for {@link DSMRMeter}.
27  *
28  * @author Hilbrand Bouwkamp - Initial contribution
29  */
30 @NonNullByDefault
31 public class DSMRMeterTest {
32
33     /**
34      * Test if method {@link DSMRMeter#filterMeterValues(List)} correctly filters values.
35      */
36     @Test
37     public void testFilterMeterValues() {
38         final List<CosemObject> cosemObjects = TelegramReaderUtil.readTelegram("dsmr_50", TelegramState.OK)
39                 .getCosemObjects();
40
41         assertMeterValues(cosemObjects, DSMRMeterType.DEVICE_V5, DSMRMeterConstants.UNKNOWN_CHANNEL, 3);
42         assertMeterValues(cosemObjects, DSMRMeterType.ELECTRICITY_V5_0, 0, 29);
43         assertMeterValues(cosemObjects, DSMRMeterType.M3_V5_0, 1, 3);
44     }
45
46     private void assertMeterValues(List<CosemObject> cosemObjects, DSMRMeterType type, int channel, int expected) {
47         final DSMRMeterDescriptor descriptor = new DSMRMeterDescriptor(type, channel);
48         final DSMRMeter meter = new DSMRMeter(descriptor);
49         final List<CosemObject> filterMeterValues = meter.filterMeterValues(cosemObjects, channel);
50
51         assertEquals(expected, filterMeterValues.size(), "Filter should return all required objects");
52     }
53 }