2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lcn.internal.subhandler;
15 import static org.mockito.Mockito.*;
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;
30 * @author Fabian Wolter - Initial contribution
33 public class LcnModuleRvarSetpointSubHandlerTest extends AbstractTestLcnModuleSubHandler {
34 private @NonNullByDefault({}) LcnModuleRvarSetpointSubHandler l;
41 l = new LcnModuleRvarSetpointSubHandler(handler, info);
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");
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");
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");
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");
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");
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");
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");
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");
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);
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);
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);
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);
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);