]> git.basschouten.com Git - openhab-addons.git/blob
f1f49d617c8baa13588966d99f7e342f23d3be11
[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 import org.openhab.core.library.types.OnOffType;
25 import org.openhab.core.library.types.StringType;
26
27 /**
28  * Test class.
29  *
30  * @author Fabian Wolter - Initial contribution
31  */
32 @NonNullByDefault
33 public class LcnModuleRvarSetpointSubHandlerTest extends AbstractTestLcnModuleSubHandler {
34     private @NonNullByDefault({}) LcnModuleRvarSetpointSubHandler l;
35
36     @Override
37     @BeforeEach
38     public void setUp() {
39         super.setUp();
40
41         l = new LcnModuleRvarSetpointSubHandler(handler, info);
42     }
43
44     @Test
45     public void testhandleCommandRvar1Positive() throws LcnException {
46         when(info.hasExtendedMeasurementProcessing()).thenReturn(true);
47         l.handleCommandDecimal(new DecimalType(1000), LcnChannelGroup.RVARSETPOINT, 0);
48         verify(handler).sendPck("X2030032000");
49     }
50
51     @Test
52     public void testhandleCommandRvar2Positive() throws LcnException {
53         when(info.hasExtendedMeasurementProcessing()).thenReturn(true);
54         l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.RVARSETPOINT, 1);
55         verify(handler).sendPck("X2030096100");
56     }
57
58     @Test
59     public void testhandleCommandRvar1Negative() throws LcnException {
60         when(info.hasExtendedMeasurementProcessing()).thenReturn(true);
61         l.handleCommandDecimal(new DecimalType(0), LcnChannelGroup.RVARSETPOINT, 0);
62         verify(handler).sendPck("X2030043232");
63     }
64
65     @Test
66     public void testhandleCommandRvar2Negative() throws LcnException {
67         when(info.hasExtendedMeasurementProcessing()).thenReturn(true);
68         l.handleCommandDecimal(new DecimalType(999), LcnChannelGroup.RVARSETPOINT, 1);
69         verify(handler).sendPck("X2030104001");
70     }
71
72     @Test
73     public void testhandleCommandRvar1PositiveLegacy() throws LcnException {
74         when(info.getVariableValue(Variable.RVARSETPOINT1)).thenReturn(1000L);
75         when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
76         l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.RVARSETPOINT, 0);
77         verify(handler).sendPck("X2030032100");
78     }
79
80     @Test
81     public void testhandleCommandRvar2PositiveLegacy() throws LcnException {
82         when(info.getVariableValue(Variable.RVARSETPOINT2)).thenReturn(1000L);
83         when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
84         l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.RVARSETPOINT, 1);
85         verify(handler).sendPck("X2030096100");
86     }
87
88     @Test
89     public void testhandleCommandRvar1NegativeLegacy() throws LcnException {
90         when(info.getVariableValue(Variable.RVARSETPOINT1)).thenReturn(1000L);
91         when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
92         l.handleCommandDecimal(new DecimalType(900), LcnChannelGroup.RVARSETPOINT, 0);
93         verify(handler).sendPck("X2030040100");
94     }
95
96     @Test
97     public void testhandleCommandRvar2NegativeLegacy() throws LcnException {
98         when(info.getVariableValue(Variable.RVARSETPOINT2)).thenReturn(1000L);
99         when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
100         l.handleCommandDecimal(new DecimalType(900), LcnChannelGroup.RVARSETPOINT, 1);
101         verify(handler).sendPck("X2030104100");
102     }
103
104     @Test
105     public void testRvar1() {
106         l.tryParse("=M000005.S11234");
107         verify(handler).updateChannel(LcnChannelGroup.RVARSETPOINT, "1", new DecimalType(1234));
108         verify(handler).updateChannel(LcnChannelGroup.RVARLOCK, "1", OnOffType.OFF);
109     }
110
111     @Test
112     public void testRvar2() {
113         l.tryParse("=M000005.S21234");
114         verify(handler).updateChannel(LcnChannelGroup.RVARSETPOINT, "2", new DecimalType(1234));
115         verify(handler).updateChannel(LcnChannelGroup.RVARLOCK, "2", OnOffType.OFF);
116     }
117
118     @Test
119     public void testRvar1SensorDefective() {
120         l.tryParse("=M000005.S132512");
121         verify(handler).updateChannel(LcnChannelGroup.RVARSETPOINT, "1", new StringType("DEFECTIVE"));
122         verify(handler).updateChannel(LcnChannelGroup.RVARLOCK, "1", OnOffType.OFF);
123     }
124
125     @Test
126     public void testRvar1Locked() {
127         l.tryParse("=M000005.S134002");
128         verify(handler).updateChannel(LcnChannelGroup.RVARSETPOINT, "1", new DecimalType(1234));
129         verify(handler).updateChannel(LcnChannelGroup.RVARLOCK, "1", OnOffType.ON);
130     }
131
132     @Test
133     public void testRvar2Locked() {
134         l.tryParse("=M000005.S234002");
135         verify(handler).updateChannel(LcnChannelGroup.RVARSETPOINT, "2", new DecimalType(1234));
136         verify(handler).updateChannel(LcnChannelGroup.RVARLOCK, "2", OnOffType.ON);
137     }
138 }