]> git.basschouten.com Git - openhab-addons.git/blob
eab1212da1884571cc91f5425423948cb01bf5cd
[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.StringType;
26
27 /**
28  * Test class.
29  *
30  * @author Fabian Wolter - Initial contribution
31  */
32 @NonNullByDefault
33 public class LcnModuleVariableSubHandlerTest extends AbstractTestLcnModuleSubHandler {
34     private @NonNullByDefault({}) LcnModuleVariableSubHandler l;
35
36     @Override
37     @BeforeEach
38     public void setUp() {
39         super.setUp();
40
41         l = new LcnModuleVariableSubHandler(handler, info);
42     }
43
44     @Test
45     public void testStatusVariable1() {
46         tryParseAllHandlers("=M000005.A00112345");
47         verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "1", new DecimalType(12345));
48         verify(handler).updateChannel(any(), any(), any());
49     }
50
51     @Test
52     public void testStatusVariable12() {
53         tryParseAllHandlers("=M000005.A01212345");
54         verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "12", new DecimalType(12345));
55         verify(handler).updateChannel(any(), any(), any());
56     }
57
58     @Test
59     public void testStatusLegacyVariable3() {
60         when(info.getLastRequestedVarWithoutTypeInResponse()).thenReturn(Variable.VARIABLE3);
61         tryParseAllHandlers("=M000005.12345");
62         verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "3", new DecimalType(12345));
63         verify(handler).updateChannel(any(), any(), any());
64     }
65
66     @Test
67     public void testHandleCommandLegacyTvarPositive() throws LcnException {
68         when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
69         when(info.getVariableValue(Variable.VARIABLE1)).thenReturn(1000L);
70         l.handleCommandDecimal(new DecimalType(1234), LcnChannelGroup.VARIABLE, 0);
71         verify(handler).sendPck("ZA234");
72     }
73
74     @Test
75     public void testHandleCommandLegacyTvarNegative() throws LcnException {
76         when(info.hasExtendedMeasurementProcessing()).thenReturn(false);
77         when(info.getVariableValue(Variable.VARIABLE1)).thenReturn(2000L);
78         l.handleCommandDecimal(new DecimalType(1100), LcnChannelGroup.VARIABLE, 0);
79         verify(handler).sendPck("ZS900");
80     }
81
82     @Test
83     public void testStatusVariable10SensorDefective() {
84         tryParseAllHandlers("=M000005.A01032512");
85         verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "10", new StringType("Sensor defective: VARIABLE10"));
86         verify(handler).updateChannel(any(), any(), any());
87     }
88
89     @Test
90     public void testStatusVariable8NotConfigured() {
91         tryParseAllHandlers("=M000005.A00865535");
92         verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "8",
93                 new StringType("Not configured in LCN-PRO: VARIABLE8"));
94         verify(handler).updateChannel(any(), any(), any());
95     }
96 }