]> git.basschouten.com Git - openhab-addons.git/blob
4700d650a085540757c03bd6b9f69ffbea6597a8
[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.smartmeter;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.junit.jupiter.api.Test;
18 import org.openhab.binding.smartmeter.internal.MeterValue;
19 import org.openhab.binding.smartmeter.internal.conformity.negate.NegateBitModel;
20 import org.openhab.binding.smartmeter.internal.conformity.negate.NegateBitParser;
21 import org.openhab.binding.smartmeter.internal.conformity.negate.NegateHandler;
22
23 /**
24  *
25  * @author Matthias Steigenberger - Initial contribution
26  *
27  */
28 public class TestNegateBit {
29
30     @Test
31     public void testNegateBitParsing() {
32         String negateProperty = "1-0_1-8-0:5:1";
33         NegateBitModel parseNegateProperty = NegateBitParser.parseNegateProperty(negateProperty);
34         assertEquals("1-0_1-8-0", parseNegateProperty.getNegateChannelId());
35         assertEquals(5, parseNegateProperty.getNegatePosition());
36         assertEquals(true, parseNegateProperty.isNegateBit());
37     }
38
39     @Test
40     public void testNegateHandlingTrue() {
41         String negateProperty = "1-0_1-8-0:5:1";
42
43         boolean negateState = NegateHandler.shouldNegateState(negateProperty, obis -> {
44             return new MeterValue<>(obis, "65954", null);
45         });
46
47         assertTrue(negateState);
48     }
49
50     @Test
51     public void testNegateHandlingFalse() {
52         String negateProperty = "1-0_1-8-0:5:1";
53
54         boolean negateState = NegateHandler.shouldNegateState(negateProperty, obis -> {
55             return new MeterValue<>(obis, "0", null, "65922");
56         });
57
58         assertFalse(negateState);
59     }
60 }