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.verify;
17 import java.math.BigDecimal;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.BeforeEach;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.lcn.internal.common.DimmerOutputCommand;
23 import org.openhab.binding.lcn.internal.common.LcnChannelGroup;
24 import org.openhab.binding.lcn.internal.common.LcnDefs;
25 import org.openhab.binding.lcn.internal.common.LcnException;
26 import org.openhab.core.library.types.OnOffType;
27 import org.openhab.core.library.types.PercentType;
32 * @author Fabian Wolter - Initial contribution
35 public class LcnModuleOutputSubHandlerTest extends AbstractTestLcnModuleSubHandler {
36 private @NonNullByDefault({}) LcnModuleOutputSubHandler l;
43 l = new LcnModuleOutputSubHandler(handler, info);
47 public void testStatusOutput1OffPercent() {
48 l.tryParse("=M000005A1000");
49 verify(handler).updateChannel(LcnChannelGroup.OUTPUT, "1", new PercentType(0));
53 public void testStatusOutput2OffPercent() {
54 l.tryParse("=M000005A2000");
55 verify(handler).updateChannel(LcnChannelGroup.OUTPUT, "2", new PercentType(0));
59 public void testStatusOutput1OffNative() {
60 l.tryParse("=M000005O1000");
61 verify(handler).updateChannel(LcnChannelGroup.OUTPUT, "1", new PercentType(0));
65 public void testStatusOutput2OffNative() {
66 l.tryParse("=M000005O2000");
67 verify(handler).updateChannel(LcnChannelGroup.OUTPUT, "2", new PercentType(0));
71 public void testStatusOutput1OnPercent() {
72 l.tryParse("=M000005A1100");
73 verify(handler).updateChannel(LcnChannelGroup.OUTPUT, "1", new PercentType(100));
77 public void testStatusOutput2OnPercent() {
78 l.tryParse("=M000005A2100");
79 verify(handler).updateChannel(LcnChannelGroup.OUTPUT, "2", new PercentType(100));
83 public void testStatusOutput1OnNative() {
84 l.tryParse("=M000005O1200");
85 verify(handler).updateChannel(LcnChannelGroup.OUTPUT, "1", new PercentType(100));
89 public void testStatusOutput2OnNative() {
90 l.tryParse("=M000005O2200");
91 verify(handler).updateChannel(LcnChannelGroup.OUTPUT, "2", new PercentType(100));
95 public void testStatusOutput2On50Percent() {
96 l.tryParse("=M000005A2050");
97 verify(handler).updateChannel(LcnChannelGroup.OUTPUT, "2", new PercentType(50));
101 public void testStatusOutput1On50Native() {
102 l.tryParse("=M000005O1100");
103 verify(handler).updateChannel(LcnChannelGroup.OUTPUT, "1", new PercentType(50));
107 public void testHandleCommandOutput1On() throws LcnException {
108 l.handleCommandOnOff(OnOffType.ON, LcnChannelGroup.OUTPUT, 0);
109 verify(handler).sendPck("A1DI100000");
113 public void testHandleCommandOutput2On() throws LcnException {
114 l.handleCommandOnOff(OnOffType.ON, LcnChannelGroup.OUTPUT, 1);
115 verify(handler).sendPck("A2DI100000");
119 public void testHandleCommandOutput1Off() throws LcnException {
120 l.handleCommandOnOff(OnOffType.OFF, LcnChannelGroup.OUTPUT, 0);
121 verify(handler).sendPck("A1DI000000");
125 public void testHandleCommandOutput2Off() throws LcnException {
126 l.handleCommandOnOff(OnOffType.OFF, LcnChannelGroup.OUTPUT, 1);
127 verify(handler).sendPck("A2DI000000");
131 public void testHandleCommandOutput1Percent10() throws LcnException {
132 l.handleCommandPercent(new PercentType(99), LcnChannelGroup.OUTPUT, 0);
133 verify(handler).sendPck("A1DI099000");
137 public void testHandleCommandOutput2Percent1() throws LcnException {
138 l.handleCommandPercent(new PercentType(1), LcnChannelGroup.OUTPUT, 1);
139 verify(handler).sendPck("A2DI001000");
143 public void testHandleCommandOutput1Percent995() throws LcnException {
144 l.handleCommandPercent(new PercentType(BigDecimal.valueOf(99.5)), LcnChannelGroup.OUTPUT, 0);
145 verify(handler).sendPck("O1DI199000");
149 public void testHandleCommandOutput2Percent05() throws LcnException {
150 l.handleCommandPercent(new PercentType(BigDecimal.valueOf(0.5)), LcnChannelGroup.OUTPUT, 1);
151 verify(handler).sendPck("O2DI001000");
155 public void testHandleCommandDimmerOutputAll60FixedRamp() throws LcnException {
156 l.handleCommandDimmerOutput(new DimmerOutputCommand(BigDecimal.valueOf(60), true, false, LcnDefs.FIXED_RAMP_MS),
158 verify(handler).sendPck("AH060");
162 public void testHandleCommandDimmerOutputAll40CustomRamp() throws LcnException {
163 l.handleCommandDimmerOutput(new DimmerOutputCommand(BigDecimal.valueOf(40), true, false, 1000), 0);
164 verify(handler).sendPck("OY080080080080004");
168 public void testHandleCommandDimmerOutput12Value100FixedRamp() throws LcnException {
169 l.handleCommandDimmerOutput(
170 new DimmerOutputCommand(BigDecimal.valueOf(100), false, true, LcnDefs.FIXED_RAMP_MS), 0);
171 verify(handler).sendPck("X2001200200");
175 public void testHandleCommandDimmerOutput12Value0FixedRamp() throws LcnException {
176 l.handleCommandDimmerOutput(new DimmerOutputCommand(BigDecimal.valueOf(0), false, true, LcnDefs.FIXED_RAMP_MS),
178 verify(handler).sendPck("X2001000000");
182 public void testHandleCommandDimmerOutput12Value100NoRamp() throws LcnException {
183 l.handleCommandDimmerOutput(new DimmerOutputCommand(BigDecimal.valueOf(100), false, true, 0), 0);
184 verify(handler).sendPck("X2001253253");
188 public void testHandleCommandDimmerOutput12Value0NoRamp() throws LcnException {
189 l.handleCommandDimmerOutput(new DimmerOutputCommand(BigDecimal.valueOf(0), false, true, 0), 0);
190 verify(handler).sendPck("X2001252252");
194 public void testHandleCommandDimmerOutput12Value40() throws LcnException {
195 l.handleCommandDimmerOutput(new DimmerOutputCommand(BigDecimal.valueOf(40), false, true, 0), 0);
196 verify(handler).sendPck("AY040040");