2 * Copyright (c) 2010-2022 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.ArgumentMatchers.any;
16 import static org.mockito.Mockito.*;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.junit.jupiter.api.BeforeEach;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.lcn.internal.common.LcnChannelGroup;
22 import org.openhab.binding.lcn.internal.common.LcnException;
23 import org.openhab.binding.lcn.internal.common.Variable;
24 import org.openhab.core.library.types.DecimalType;
29 * @author Fabian Wolter - Initial contribution
32 public class LcnModuleThresholdSubHandlerTest extends AbstractTestLcnModuleSubHandler {
33 private @NonNullByDefault({}) LcnModuleThresholdSubHandler l;
40 l = new LcnModuleThresholdSubHandler(handler, info);
44 public void testThreshold11() {
45 tryParseAllHandlers("=M000005.T1112345");
46 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "1", new DecimalType(12345));
47 verify(handler).updateChannel(any(), any(), any());
51 public void testThreshold14() {
52 tryParseAllHandlers("=M000005.T140");
53 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "4", new DecimalType(0));
54 verify(handler).updateChannel(any(), any(), any());
58 public void testThreshold41() {
59 tryParseAllHandlers("=M000005.T4112345");
60 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER4, "1", new DecimalType(12345));
61 verify(handler).updateChannel(any(), any(), any());
65 public void testThresholdLegacy() {
66 tryParseAllHandlers("=M000005.S1123451123411123000000000112345");
67 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "1", new DecimalType(12345));
68 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "2", new DecimalType(11234));
69 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "3", new DecimalType(11123));
70 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "4", new DecimalType(0));
71 verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "5", new DecimalType(1));
72 verify(handler, times(5)).updateChannel(any(), any(), any());
76 public void testhandleCommandThreshold11Positive() throws LcnException {
77 when(info.getVariableValue(Variable.THRESHOLDREGISTER11)).thenReturn(1000L);
78 when(info.hasExtendedMeasurementProcessing()).thenReturn(true);
79 l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.THRESHOLDREGISTER1, 0);
80 verify(handler).sendPck("SSR0100AR11");
84 public void testhandleCommandThreshold11Negative() throws LcnException {
85 when(info.getVariableValue(Variable.THRESHOLDREGISTER11)).thenReturn(1000L);
86 when(info.hasExtendedMeasurementProcessing()).thenReturn(true);
87 l.handleCommandDecimal(new DecimalType(900), LcnChannelGroup.THRESHOLDREGISTER1, 0);
88 verify(handler).sendPck("SSR0100SR11");
92 public void testhandleCommandThreshold44Positive() throws LcnException {
93 when(info.getVariableValue(Variable.THRESHOLDREGISTER44)).thenReturn(1000L);
94 when(info.hasExtendedMeasurementProcessing()).thenReturn(true);
95 l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.THRESHOLDREGISTER4, 3);
96 verify(handler).sendPck("SSR0100AR44");
100 public void testhandleCommandThreshold44Negative() throws LcnException {
101 when(info.getVariableValue(Variable.THRESHOLDREGISTER44)).thenReturn(1000L);
102 when(info.hasExtendedMeasurementProcessing()).thenReturn(true);
103 l.handleCommandDecimal(new DecimalType(900), LcnChannelGroup.THRESHOLDREGISTER4, 3);
104 verify(handler).sendPck("SSR0100SR44");
108 public void testhandleCommandThreshold11LegacyPositive() throws LcnException {
109 when(info.getVariableValue(Variable.THRESHOLDREGISTER11)).thenReturn(1000L);
110 when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
111 l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.THRESHOLDREGISTER1, 0);
112 verify(handler).sendPck("SSR0100A10000");
116 public void testhandleCommandThreshold11LegacyNegative() throws LcnException {
117 when(info.getVariableValue(Variable.THRESHOLDREGISTER11)).thenReturn(1000L);
118 when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
119 l.handleCommandDecimal(new DecimalType(900), LcnChannelGroup.THRESHOLDREGISTER1, 0);
120 verify(handler).sendPck("SSR0100S10000");
124 public void testhandleCommandThreshold14Legacy() throws LcnException {
125 when(info.getVariableValue(Variable.THRESHOLDREGISTER14)).thenReturn(1000L);
126 when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
127 l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.THRESHOLDREGISTER1, 3);
128 verify(handler).sendPck("SSR0100A00010");
132 public void testhandleCommandThreshold15Legacy() throws LcnException {
133 when(info.getVariableValue(Variable.THRESHOLDREGISTER15)).thenReturn(1000L);
134 when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
135 l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.THRESHOLDREGISTER1, 4);
136 verify(handler).sendPck("SSR0100A00001");