2 * Copyright (c) 2010-2021 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.StringType;
29 * @author Fabian Wolter - Initial contribution
32 public class LcnModuleVariableSubHandlerTest extends AbstractTestLcnModuleSubHandler {
33 private @NonNullByDefault({}) LcnModuleVariableSubHandler l;
40 l = new LcnModuleVariableSubHandler(handler, info);
44 public void testStatusVariable1() {
45 l.tryParse("=M000005.A00112345");
46 verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "1", new DecimalType(12345));
50 public void testStatusVariable12() {
51 l.tryParse("=M000005.A01212345");
52 verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "12", new DecimalType(12345));
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));
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");
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");
79 public void testStatusVariable10SensorDefective() {
80 l.tryParse("=M000005.A01032512");
81 verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "10", new StringType("DEFECTIVE"));
85 public void testStatusVariable8NotConfigured() {
86 l.tryParse("=M000005.A00865535");
87 verify(handler).updateChannel(LcnChannelGroup.VARIABLE, "8", new StringType("Not configured in LCN-PRO"));