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.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.core.library.types.OnOffType;
24 import org.openhab.core.library.types.PercentType;
25 import org.openhab.core.library.types.UpDownType;
30 * @author Fabian Wolter - Initial contribution
33 public class LcnModuleRelaySubHandlerTest extends AbstractTestLcnModuleSubHandler {
34 private @NonNullByDefault({}) LcnModuleRelaySubHandler l;
41 l = new LcnModuleRelaySubHandler(handler, info);
45 public void testStatusAllOff() {
46 tryParseAllHandlers("=M000005Rx000");
47 verify(handler).updateChannel(LcnChannelGroup.RELAY, "1", OnOffType.OFF);
48 verify(handler).updateChannel(LcnChannelGroup.RELAY, "2", OnOffType.OFF);
49 verify(handler).updateChannel(LcnChannelGroup.RELAY, "3", OnOffType.OFF);
50 verify(handler).updateChannel(LcnChannelGroup.RELAY, "4", OnOffType.OFF);
51 verify(handler).updateChannel(LcnChannelGroup.RELAY, "5", OnOffType.OFF);
52 verify(handler).updateChannel(LcnChannelGroup.RELAY, "6", OnOffType.OFF);
53 verify(handler).updateChannel(LcnChannelGroup.RELAY, "7", OnOffType.OFF);
54 verify(handler).updateChannel(LcnChannelGroup.RELAY, "8", OnOffType.OFF);
55 verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "1", UpDownType.UP);
56 verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "2", UpDownType.UP);
57 verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "3", UpDownType.UP);
58 verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "4", UpDownType.UP);
59 verify(handler, times(12)).updateChannel(any(), any(), any());
63 public void testStatusAllOn() {
64 tryParseAllHandlers("=M000005Rx255");
65 verify(handler).updateChannel(LcnChannelGroup.RELAY, "1", OnOffType.ON);
66 verify(handler).updateChannel(LcnChannelGroup.RELAY, "2", OnOffType.ON);
67 verify(handler).updateChannel(LcnChannelGroup.RELAY, "3", OnOffType.ON);
68 verify(handler).updateChannel(LcnChannelGroup.RELAY, "5", OnOffType.ON);
69 verify(handler).updateChannel(LcnChannelGroup.RELAY, "6", OnOffType.ON);
70 verify(handler).updateChannel(LcnChannelGroup.RELAY, "7", OnOffType.ON);
71 verify(handler).updateChannel(LcnChannelGroup.RELAY, "8", OnOffType.ON);
72 verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "1", UpDownType.DOWN);
73 verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "2", UpDownType.DOWN);
74 verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "3", UpDownType.DOWN);
75 verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "4", UpDownType.DOWN);
76 verify(handler, times(12)).updateChannel(any(), any(), any());
80 public void testStatusRelay1Relay7On() {
81 tryParseAllHandlers("=M000005Rx065");
82 verify(handler).updateChannel(LcnChannelGroup.RELAY, "1", OnOffType.ON);
83 verify(handler).updateChannel(LcnChannelGroup.RELAY, "2", OnOffType.OFF);
84 verify(handler).updateChannel(LcnChannelGroup.RELAY, "3", OnOffType.OFF);
85 verify(handler).updateChannel(LcnChannelGroup.RELAY, "4", OnOffType.OFF);
86 verify(handler).updateChannel(LcnChannelGroup.RELAY, "5", OnOffType.OFF);
87 verify(handler).updateChannel(LcnChannelGroup.RELAY, "6", OnOffType.OFF);
88 verify(handler).updateChannel(LcnChannelGroup.RELAY, "7", OnOffType.ON);
89 verify(handler).updateChannel(LcnChannelGroup.RELAY, "8", OnOffType.OFF);
90 verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "1", UpDownType.UP);
91 verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "2", UpDownType.UP);
92 verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "3", UpDownType.UP);
93 verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "4", UpDownType.UP);
94 verify(handler, times(12)).updateChannel(any(), any(), any());
98 public void testHandleCommandRelay1On() throws LcnException {
99 l.handleCommandOnOff(OnOffType.ON, LcnChannelGroup.RELAY, 0);
100 verify(handler).sendPck("R81-------");
104 public void testHandleCommandRelay8On() throws LcnException {
105 l.handleCommandOnOff(OnOffType.ON, LcnChannelGroup.RELAY, 7);
106 verify(handler).sendPck("R8-------1");
110 public void testHandleCommandRelay1Off() throws LcnException {
111 l.handleCommandOnOff(OnOffType.OFF, LcnChannelGroup.RELAY, 0);
112 verify(handler).sendPck("R80-------");
116 public void testHandleCommandRelay8Off() throws LcnException {
117 l.handleCommandOnOff(OnOffType.OFF, LcnChannelGroup.RELAY, 7);
118 verify(handler).sendPck("R8-------0");
122 public void testHandleCommandRelay8Percent1() throws LcnException {
123 l.handleCommandPercent(new PercentType(1), LcnChannelGroup.RELAY, 7);
124 verify(handler).sendPck("R8-------1");
128 public void testHandleCommandRelay1Percent0() throws LcnException {
129 l.handleCommandPercent(PercentType.ZERO, LcnChannelGroup.RELAY, 0);