]> git.basschouten.com Git - openhab-addons.git/blob
1b59dceb618e688beb1845f8cc554f96da8b37d4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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,
44                 obis -> new MeterValue<>(obis, "65954", null));
45
46         assertTrue(negateState);
47     }
48
49     @Test
50     public void testNegateHandlingFalse() {
51         String negateProperty = "1-0_1-8-0:5:1";
52
53         boolean negateState = NegateHandler.shouldNegateState(negateProperty,
54                 obis -> new MeterValue<>(obis, "0", null, "65922"));
55
56         assertFalse(negateState);
57     }
58 }