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