]> git.basschouten.com Git - openhab-addons.git/blob
4b6de5643c5cbbe65b557cd8df96909607a6dda6
[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 testNegateHandlingDecimalTrue() {
51         String negateProperty = "1-0_16-7-0:31:0";
52
53         boolean negateStateDot = NegateHandler.shouldNegateState(negateProperty,
54                 obis -> new MeterValue<>(obis, "49.0", null));
55
56         assertTrue(negateStateDot);
57     }
58
59     @Test
60     public void testNegateHandlingFalse() {
61         String negateProperty = "1-0_1-8-0:5:1";
62
63         boolean negateState = NegateHandler.shouldNegateState(negateProperty,
64                 obis -> new MeterValue<>(obis, "0", null, "65922"));
65
66         assertFalse(negateState);
67     }
68 }