2 * Copyright (c) 2010-2021 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.lcn.internal.subhandler;
15 import static org.mockito.Mockito.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.BeforeEach;
19 import org.junit.jupiter.api.Test;
20 import org.openhab.binding.lcn.internal.common.LcnChannelGroup;
21 import org.openhab.binding.lcn.internal.common.LcnException;
22 import org.openhab.binding.lcn.internal.common.Variable;
23 import org.openhab.core.library.types.DecimalType;
28 * @author Fabian Wolter - Initial contribution
31 public class LcnModuleThresholdSubHandlerTest extends AbstractTestLcnModuleSubHandler {
32 private @NonNullByDefault({}) LcnModuleThresholdSubHandler l;
39 l = new LcnModuleThresholdSubHandler(handler, info);
43 public void testThreshold11() {
44 l.tryParse("=M000005.T1112345");
45 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "1", new DecimalType(12345));
49 public void testThreshold14() {
50 l.tryParse("=M000005.T140");
51 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "4", new DecimalType(0));
55 public void testThreshold41() {
56 l.tryParse("=M000005.T4112345");
57 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER4, "1", new DecimalType(12345));
61 public void testThresholdLegacy() {
62 l.tryParse("=M000005.S1123451123411123000000000112345");
63 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "1", new DecimalType(12345));
64 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "2", new DecimalType(11234));
65 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "3", new DecimalType(11123));
66 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "4", new DecimalType(0));
67 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "5", new DecimalType(1));
71 public void testhandleCommandThreshold11Positive() throws LcnException {
72 when(info.getVariableValue(Variable.THRESHOLDREGISTER11)).thenReturn(1000L);
73 when(info.hasExtendedMeasurementProcessing()).thenReturn(true);
74 l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.THRESHOLDREGISTER1, 0);
75 verify(handler).sendPck("SSR0100AR11");
79 public void testhandleCommandThreshold11Negative() throws LcnException {
80 when(info.getVariableValue(Variable.THRESHOLDREGISTER11)).thenReturn(1000L);
81 when(info.hasExtendedMeasurementProcessing()).thenReturn(true);
82 l.handleCommandDecimal(new DecimalType(900), LcnChannelGroup.THRESHOLDREGISTER1, 0);
83 verify(handler).sendPck("SSR0100SR11");
87 public void testhandleCommandThreshold44Positive() throws LcnException {
88 when(info.getVariableValue(Variable.THRESHOLDREGISTER44)).thenReturn(1000L);
89 when(info.hasExtendedMeasurementProcessing()).thenReturn(true);
90 l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.THRESHOLDREGISTER4, 3);
91 verify(handler).sendPck("SSR0100AR44");
95 public void testhandleCommandThreshold44Negative() throws LcnException {
96 when(info.getVariableValue(Variable.THRESHOLDREGISTER44)).thenReturn(1000L);
97 when(info.hasExtendedMeasurementProcessing()).thenReturn(true);
98 l.handleCommandDecimal(new DecimalType(900), LcnChannelGroup.THRESHOLDREGISTER4, 3);
99 verify(handler).sendPck("SSR0100SR44");
103 public void testhandleCommandThreshold11LegacyPositive() throws LcnException {
104 when(info.getVariableValue(Variable.THRESHOLDREGISTER11)).thenReturn(1000L);
105 when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
106 l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.THRESHOLDREGISTER1, 0);
107 verify(handler).sendPck("SSR0100A10000");
111 public void testhandleCommandThreshold11LegacyNegative() throws LcnException {
112 when(info.getVariableValue(Variable.THRESHOLDREGISTER11)).thenReturn(1000L);
113 when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
114 l.handleCommandDecimal(new DecimalType(900), LcnChannelGroup.THRESHOLDREGISTER1, 0);
115 verify(handler).sendPck("SSR0100S10000");
119 public void testhandleCommandThreshold14Legacy() throws LcnException {
120 when(info.getVariableValue(Variable.THRESHOLDREGISTER14)).thenReturn(1000L);
121 when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
122 l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.THRESHOLDREGISTER1, 3);
123 verify(handler).sendPck("SSR0100A00010");
127 public void testhandleCommandThreshold15Legacy() throws LcnException {
128 when(info.getVariableValue(Variable.THRESHOLDREGISTER15)).thenReturn(1000L);
129 when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
130 l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.THRESHOLDREGISTER1, 4);
131 verify(handler).sendPck("SSR0100A00001");