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.StringType;
30 * @author Fabian Wolter - Initial contribution
33 public class LcnModuleVariableSubHandlerTest extends AbstractTestLcnModuleSubHandler {
34 private @NonNullByDefault({}) LcnModuleVariableSubHandler l;
41 l = new LcnModuleVariableSubHandler(handler, info);
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());
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());
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());
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");
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");
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());
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());