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