]> git.basschouten.com Git - openhab-addons.git/blob
bb924a4dddd19e1f3d7c73ad5d1cfbee6a527ef6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.ArgumentMatchers.any;
16 import static org.mockito.Mockito.verify;
17
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.PercentType;
24 import org.openhab.core.library.types.StopMoveType;
25 import org.openhab.core.library.types.UpDownType;
26
27 /**
28  * Test class.
29  *
30  * @author Fabian Wolter - Initial contribution
31  */
32 @NonNullByDefault
33 public class AbstractLcnModuleRollershutterRelaySubHandlerTest extends AbstractTestLcnModuleSubHandler {
34     private @NonNullByDefault({}) AbstractLcnModuleRollershutterRelaySubHandler l;
35
36     @Override
37     @BeforeEach
38     public void setUp() {
39         super.setUp();
40
41         l = new AbstractLcnModuleRollershutterRelaySubHandler(handler, info) {
42         };
43     }
44
45     @Test
46     public void testUp1() throws LcnException {
47         l.handleCommandUpDown(UpDownType.UP, LcnChannelGroup.ROLLERSHUTTERRELAY, 0, false);
48         verify(handler).sendPck("R810------");
49     }
50
51     @Test
52     public void testUpInverted() throws LcnException {
53         l.handleCommandUpDown(UpDownType.UP, LcnChannelGroup.ROLLERSHUTTERRELAY, 0, true);
54         verify(handler).sendPck("R811------");
55     }
56
57     @Test
58     public void testUp4() throws LcnException {
59         l.handleCommandUpDown(UpDownType.UP, LcnChannelGroup.ROLLERSHUTTERRELAY, 3, false);
60         verify(handler).sendPck("R8------10");
61     }
62
63     @Test
64     public void testDown1() throws LcnException {
65         l.handleCommandUpDown(UpDownType.DOWN, LcnChannelGroup.ROLLERSHUTTERRELAY, 0, false);
66         verify(handler).sendPck("R811------");
67     }
68
69     @Test
70     public void testDownInverted() throws LcnException {
71         l.handleCommandUpDown(UpDownType.DOWN, LcnChannelGroup.ROLLERSHUTTERRELAY, 0, true);
72         verify(handler).sendPck("R810------");
73     }
74
75     @Test
76     public void testDown4() throws LcnException {
77         l.handleCommandUpDown(UpDownType.DOWN, LcnChannelGroup.ROLLERSHUTTERRELAY, 3, false);
78         verify(handler).sendPck("R8------11");
79     }
80
81     @Test
82     public void testStop1() throws LcnException {
83         l.handleCommandStopMove(StopMoveType.STOP, LcnChannelGroup.ROLLERSHUTTERRELAY, 0);
84         verify(handler).sendPck("R80-------");
85     }
86
87     @Test
88     public void testStop4() throws LcnException {
89         l.handleCommandStopMove(StopMoveType.STOP, LcnChannelGroup.ROLLERSHUTTERRELAY, 3);
90         verify(handler).sendPck("R8------0-");
91     }
92
93     @Test
94     public void testMove1() throws LcnException {
95         l.handleCommandStopMove(StopMoveType.MOVE, LcnChannelGroup.ROLLERSHUTTERRELAY, 0);
96         verify(handler).sendPck("R81-------");
97     }
98
99     @Test
100     public void testMove4() throws LcnException {
101         l.handleCommandStopMove(StopMoveType.MOVE, LcnChannelGroup.ROLLERSHUTTERRELAY, 3);
102         verify(handler).sendPck("R8------1-");
103     }
104
105     @Test
106     public void testShutter1Percent0Position() {
107         tryParseAllHandlers(":M000005P1000");
108         verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "1", new PercentType(0));
109         verify(handler).updateChannel(any(), any(), any());
110     }
111
112     @Test
113     public void testShutter4Percent100Position() {
114         tryParseAllHandlers(":M000005P4100");
115         verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAY, "4", new PercentType(100));
116         verify(handler).updateChannel(any(), any(), any());
117     }
118
119     @Test
120     public void testShutter1Percent0Angle() {
121         tryParseAllHandlers(":M000005W1000");
122         verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAYSLAT, "1", new PercentType(0));
123         verify(handler).updateChannel(any(), any(), any());
124     }
125
126     @Test
127     public void testShutter4Percent100Angle() {
128         tryParseAllHandlers(":M000005W4100");
129         verify(handler).updateChannel(LcnChannelGroup.ROLLERSHUTTERRELAYSLAT, "4", new PercentType(100));
130         verify(handler).updateChannel(any(), any(), any());
131     }
132 }