]> git.basschouten.com Git - openhab-addons.git/blob
2eb71ad719642ad02d8a2a0308e7b06b56b669c8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.lcn.internal.subhandler;
14
15 import static org.mockito.ArgumentMatchers.any;
16 import static org.mockito.Mockito.*;
17
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;
25
26 /**
27  * Test class.
28  *
29  * @author Fabian Wolter - Initial contribution
30  */
31 @NonNullByDefault
32 public class LcnModuleThresholdSubHandlerTest extends AbstractTestLcnModuleSubHandler {
33     private @NonNullByDefault({}) LcnModuleThresholdSubHandler l;
34
35     @Override
36     @BeforeEach
37     public void setUp() {
38         super.setUp();
39
40         l = new LcnModuleThresholdSubHandler(handler, info);
41     }
42
43     @Test
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());
48     }
49
50     @Test
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());
55     }
56
57     @Test
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());
62     }
63
64     @Test
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());
73     }
74
75     @Test
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");
81     }
82
83     @Test
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");
89     }
90
91     @Test
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");
97     }
98
99     @Test
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");
105     }
106
107     @Test
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");
113     }
114
115     @Test
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");
121     }
122
123     @Test
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");
129     }
130
131     @Test
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");
137     }
138 }