]> git.basschouten.com Git - openhab-addons.git/blob
e93e6081e61e314f940e01da8e25091618a3e9b5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lcn.internal.subhandler;
14
15 import static org.mockito.Mockito.verify;
16
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;
24
25 /**
26  * Test class.
27  *
28  * @author Fabian Wolter - Initial contribution
29  */
30 @NonNullByDefault
31 public class LcnModuleRelaySubHandlerTest extends AbstractTestLcnModuleSubHandler {
32     private @NonNullByDefault({}) LcnModuleRelaySubHandler l;
33
34     @Override
35     @BeforeEach
36     public void setUp() {
37         super.setUp();
38
39         l = new LcnModuleRelaySubHandler(handler, info);
40     }
41
42     @Test
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);
53     }
54
55     @Test
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);
65     }
66
67     @Test
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);
78     }
79
80     @Test
81     public void testHandleCommandRelay1On() throws LcnException {
82         l.handleCommandOnOff(OnOffType.ON, LcnChannelGroup.RELAY, 0);
83         verify(handler).sendPck("R81-------");
84     }
85
86     @Test
87     public void testHandleCommandRelay8On() throws LcnException {
88         l.handleCommandOnOff(OnOffType.ON, LcnChannelGroup.RELAY, 7);
89         verify(handler).sendPck("R8-------1");
90     }
91
92     @Test
93     public void testHandleCommandRelay1Off() throws LcnException {
94         l.handleCommandOnOff(OnOffType.OFF, LcnChannelGroup.RELAY, 0);
95         verify(handler).sendPck("R80-------");
96     }
97
98     @Test
99     public void testHandleCommandRelay8Off() throws LcnException {
100         l.handleCommandOnOff(OnOffType.OFF, LcnChannelGroup.RELAY, 7);
101         verify(handler).sendPck("R8-------0");
102     }
103
104     @Test
105     public void testHandleCommandRelay8Percent1() throws LcnException {
106         l.handleCommandPercent(new PercentType(1), LcnChannelGroup.RELAY, 7);
107         verify(handler).sendPck("R8-------1");
108     }
109
110     @Test
111     public void testHandleCommandRelay1Percent0() throws LcnException {
112         l.handleCommandPercent(PercentType.ZERO, LcnChannelGroup.RELAY, 0);
113     }
114 }