2 * Copyright (c) 2010-2023 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.ArgumentMatchers.any;
16 import static org.mockito.Mockito.*;
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;
31 * @author Fabian Wolter - Initial contribution
34 public class LcnModuleRvarSetpointSubHandlerTest extends AbstractTestLcnModuleSubHandler {
35 private @NonNullByDefault({}) LcnModuleRvarSetpointSubHandler l;
42 l = new LcnModuleRvarSetpointSubHandler(handler, info);
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");
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");
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");
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");
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");
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");
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");
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");
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());
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());
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());
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());
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());