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 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.core.library.types.OnOffType;
23 import org.openhab.core.library.types.PercentType;
28 * @author Fabian Wolter - Initial contribution
31 public class LcnModuleRelaySubHandlerTest extends AbstractTestLcnModuleSubHandler {
32 private @NonNullByDefault({}) LcnModuleRelaySubHandler l;
39 l = new LcnModuleRelaySubHandler(handler, info);
43 public void testStatusAllOff() {
44 l.tryParse("=M000005Rx000");
45 verify(handler).updateChannel(LcnChannelGroup.RELAY, "1", OnOffType.OFF);
46 verify(handler).updateChannel(LcnChannelGroup.RELAY, "2", OnOffType.OFF);
47 verify(handler).updateChannel(LcnChannelGroup.RELAY, "3", OnOffType.OFF);
48 verify(handler).updateChannel(LcnChannelGroup.RELAY, "4", OnOffType.OFF);
49 verify(handler).updateChannel(LcnChannelGroup.RELAY, "5", OnOffType.OFF);
50 verify(handler).updateChannel(LcnChannelGroup.RELAY, "6", OnOffType.OFF);
51 verify(handler).updateChannel(LcnChannelGroup.RELAY, "7", OnOffType.OFF);
52 verify(handler).updateChannel(LcnChannelGroup.RELAY, "8", OnOffType.OFF);
56 public void testStatusAllOn() {
57 l.tryParse("=M000005Rx255");
58 verify(handler).updateChannel(LcnChannelGroup.RELAY, "1", OnOffType.ON);
59 verify(handler).updateChannel(LcnChannelGroup.RELAY, "2", OnOffType.ON);
60 verify(handler).updateChannel(LcnChannelGroup.RELAY, "3", OnOffType.ON);
61 verify(handler).updateChannel(LcnChannelGroup.RELAY, "5", OnOffType.ON);
62 verify(handler).updateChannel(LcnChannelGroup.RELAY, "6", OnOffType.ON);
63 verify(handler).updateChannel(LcnChannelGroup.RELAY, "7", OnOffType.ON);
64 verify(handler).updateChannel(LcnChannelGroup.RELAY, "8", OnOffType.ON);
68 public void testStatusRelay1Relay7On() {
69 l.tryParse("=M000005Rx065");
70 verify(handler).updateChannel(LcnChannelGroup.RELAY, "1", OnOffType.ON);
71 verify(handler).updateChannel(LcnChannelGroup.RELAY, "2", OnOffType.OFF);
72 verify(handler).updateChannel(LcnChannelGroup.RELAY, "3", OnOffType.OFF);
73 verify(handler).updateChannel(LcnChannelGroup.RELAY, "4", OnOffType.OFF);
74 verify(handler).updateChannel(LcnChannelGroup.RELAY, "5", OnOffType.OFF);
75 verify(handler).updateChannel(LcnChannelGroup.RELAY, "6", OnOffType.OFF);
76 verify(handler).updateChannel(LcnChannelGroup.RELAY, "7", OnOffType.ON);
77 verify(handler).updateChannel(LcnChannelGroup.RELAY, "8", OnOffType.OFF);
81 public void testHandleCommandRelay1On() throws LcnException {
82 l.handleCommandOnOff(OnOffType.ON, LcnChannelGroup.RELAY, 0);
83 verify(handler).sendPck("R81-------");
87 public void testHandleCommandRelay8On() throws LcnException {
88 l.handleCommandOnOff(OnOffType.ON, LcnChannelGroup.RELAY, 7);
89 verify(handler).sendPck("R8-------1");
93 public void testHandleCommandRelay1Off() throws LcnException {
94 l.handleCommandOnOff(OnOffType.OFF, LcnChannelGroup.RELAY, 0);
95 verify(handler).sendPck("R80-------");
99 public void testHandleCommandRelay8Off() throws LcnException {
100 l.handleCommandOnOff(OnOffType.OFF, LcnChannelGroup.RELAY, 7);
101 verify(handler).sendPck("R8-------0");
105 public void testHandleCommandRelay8Percent1() throws LcnException {
106 l.handleCommandPercent(new PercentType(1), LcnChannelGroup.RELAY, 7);
107 verify(handler).sendPck("R8-------1");
111 public void testHandleCommandRelay1Percent0() throws LcnException {
112 l.handleCommandPercent(PercentType.ZERO, LcnChannelGroup.RELAY, 0);