]> git.basschouten.com Git - openhab-addons.git/blob
175fdfa2c1e01c1c3cca9c32be9e151c6fb72ab2
[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.max.internal.command;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19
20 /**
21  * Tests cases for {@link ZCommand}.
22  *
23  * @author Marcel Verpaalen - Initial contribution
24  */
25 @NonNullByDefault
26 public class ZCommandTest {
27
28     @Test
29     public void prefixTest() {
30         ZCommand scmd = new ZCommand(ZCommand.WakeUpType.DEVICE, "0b0da3", 30);
31
32         String commandStr = scmd.getCommandString();
33         String prefix = commandStr.substring(0, 2);
34
35         assertEquals("z:", prefix);
36     }
37
38     @Test
39     public void baseCommandTest() {
40         ZCommand scmd = new ZCommand(ZCommand.WakeUpType.DEVICE, "0b0da3", 30);
41         String commandStr = scmd.getCommandString();
42         assertEquals("z:1E,D,0b0da3" + '\r' + '\n', commandStr);
43     }
44
45     @Test
46     public void wakeAllTest() {
47         ZCommand scmd = new ZCommand(ZCommand.WakeUpType.ALL, "0b0da3", 60);
48         String commandStr = scmd.getCommandString();
49         assertEquals("z:3C,A" + '\r' + '\n', commandStr);
50
51         scmd = ZCommand.wakeupAllDevices();
52         commandStr = scmd.getCommandString();
53         assertEquals("z:1E,A" + '\r' + '\n', commandStr);
54
55         scmd = ZCommand.wakeupAllDevices(60);
56         commandStr = scmd.getCommandString();
57         assertEquals("z:3C,A" + '\r' + '\n', commandStr);
58     }
59
60     @Test
61     public void wakeRoomTest() {
62         ZCommand scmd = new ZCommand(ZCommand.WakeUpType.ROOM, "01", 30);
63         String commandStr = scmd.getCommandString();
64         assertEquals("z:1E,G,01" + '\r' + '\n', commandStr);
65
66         scmd = ZCommand.wakeupRoom(1);
67         commandStr = scmd.getCommandString();
68         assertEquals("z:1E,G,01" + '\r' + '\n', commandStr);
69
70         scmd = ZCommand.wakeupRoom(2, 60);
71         commandStr = scmd.getCommandString();
72         assertEquals("z:3C,G,02" + '\r' + '\n', commandStr);
73     }
74
75     @Test
76     public void wakeDeviceTest() {
77         ZCommand scmd = ZCommand.wakeupDevice("0b0da3");
78         String commandStr = scmd.getCommandString();
79         assertEquals("z:1E,D,0b0da3" + '\r' + '\n', commandStr);
80
81         scmd = ZCommand.wakeupDevice("0b0da3", 60);
82         commandStr = scmd.getCommandString();
83         assertEquals("z:3C,D,0b0da3" + '\r' + '\n', commandStr);
84     }
85 }