2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.smartmeter;
15 import static org.junit.jupiter.api.Assertions.*;
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;
25 * @author Matthias Steigenberger - Initial contribution
28 public class TestNegateBit {
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());
40 public void testNegateHandlingTrue() {
41 String negateProperty = "1-0_1-8-0:5:1";
43 boolean negateState = NegateHandler.shouldNegateState(negateProperty,
44 obis -> new MeterValue<>(obis, "65954", null));
46 assertTrue(negateState);
50 public void testNegateHandlingDecimalTrue() {
51 String negateProperty = "1-0_16-7-0:31:0";
53 boolean negateStateDot = NegateHandler.shouldNegateState(negateProperty,
54 obis -> new MeterValue<>(obis, "49.0", null));
56 assertTrue(negateStateDot);
60 public void testNegateHandlingFalse() {
61 String negateProperty = "1-0_1-8-0:5:1";
63 boolean negateState = NegateHandler.shouldNegateState(negateProperty,
64 obis -> new MeterValue<>(obis, "0", null, "65922"));
66 assertFalse(negateState);