]> git.basschouten.com Git - openhab-addons.git/blob
a1e0625202003ff6c2e232708713174eeb5b32ae
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.Mockito.*;
16
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;
24
25 /**
26  * Test class.
27  *
28  * @author Fabian Wolter - Initial contribution
29  */
30 @NonNullByDefault
31 public class LcnModuleThresholdSubHandlerTest extends AbstractTestLcnModuleSubHandler {
32     private @NonNullByDefault({}) LcnModuleThresholdSubHandler l;
33
34     @Override
35     @BeforeEach
36     public void setUp() {
37         super.setUp();
38
39         l = new LcnModuleThresholdSubHandler(handler, info);
40     }
41
42     @Test
43     public void testThreshold11() {
44         l.tryParse("=M000005.T1112345");
45         verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "1", new DecimalType(12345));
46     }
47
48     @Test
49     public void testThreshold14() {
50         l.tryParse("=M000005.T140");
51         verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER1, "4", new DecimalType(0));
52     }
53
54     @Test
55     public void testThreshold41() {
56         l.tryParse("=M000005.T4112345");
57         verify(handler).updateChannel(LcnChannelGroup.THRESHOLDREGISTER4, "1", new DecimalType(12345));
58     }
59
60     @Test
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));
68     }
69
70     @Test
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");
76     }
77
78     @Test
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");
84     }
85
86     @Test
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");
92     }
93
94     @Test
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");
100     }
101
102     @Test
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");
108     }
109
110     @Test
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");
116     }
117
118     @Test
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");
124     }
125
126     @Test
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");
132     }
133 }