]> git.basschouten.com Git - openhab-addons.git/blob
dd8558b719104f72a186044e1315dd114f1a9994
[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.rfxcom.internal.messages;
14
15 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
16 import static org.openhab.binding.rfxcom.internal.messages.RFXComInterfaceMessage.TransceiverType._433_92MHZ_TRANSCEIVER;
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.rfxcom.internal.config.RFXComBridgeConfiguration;
22 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
23 import org.openhab.core.util.HexUtils;
24
25 /**
26  * Test for RFXCom-binding
27  *
28  * @author Mike Jagdis - Initial contribution
29  */
30 @NonNullByDefault
31 public class RFXComInterfaceControlMessageTest {
32     private RFXComBridgeConfiguration configuration = new RFXComBridgeConfiguration();
33
34     @BeforeEach
35     public void resetConfig() {
36         configuration.transmitPower = -18;
37         configuration.enableUndecoded = false;
38         configuration.enableImagintronixOpus = false;
39         configuration.enableByronSX = false;
40         configuration.enableRSL = false;
41         configuration.enableLighting4 = false;
42         configuration.enableFineOffsetViking = false;
43         configuration.enableRubicson = false;
44         configuration.enableAEBlyss = false;
45
46         configuration.enableBlindsT1T2T3T4 = false;
47         configuration.enableBlindsT0 = false;
48         configuration.enableProGuard = false;
49         // configuration.enableFS20Packets = false;
50         configuration.enableLaCrosse = false;
51         configuration.enableHidekiUPM = false;
52         configuration.enableADLightwaveRF = false;
53         configuration.enableMertik = false;
54
55         configuration.enableVisonic = false;
56         configuration.enableATI = false;
57         configuration.enableOregonScientific = false;
58         configuration.enableMeiantech = false;
59         configuration.enableHomeEasyEU = false;
60         configuration.enableAC = false;
61         configuration.enableARC = false;
62         configuration.enableX10 = false;
63     }
64
65     private void testMessage(RFXComInterfaceMessage.TransceiverType transceiverType,
66             RFXComBridgeConfiguration configuration, String data) {
67         assertArrayEquals(HexUtils.hexToBytes(data),
68                 new RFXComInterfaceControlMessage(transceiverType, configuration).decodeMessage());
69     }
70
71     @Test
72     public void testUndecodedMessage() throws RFXComException {
73         configuration.enableUndecoded = true;
74         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530080000000000000");
75     }
76
77     @Test
78     public void testImagintronixOpusMessage() throws RFXComException {
79         configuration.enableImagintronixOpus = true;
80         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530040000000000000");
81     }
82
83     @Test
84     public void testByronSXMessage() throws RFXComException {
85         configuration.enableByronSX = true;
86         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530020000000000000");
87     }
88
89     @Test
90     public void testRSLMessage() throws RFXComException {
91         configuration.enableRSL = true;
92         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530010000000000000");
93     }
94
95     @Test
96     public void testLighting4Message() throws RFXComException {
97         configuration.enableLighting4 = true;
98         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530008000000000000");
99     }
100
101     @Test
102     public void testFineOffsetVikingMessage() throws RFXComException {
103         configuration.enableFineOffsetViking = true;
104         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530004000000000000");
105     }
106
107     @Test
108     public void testRubicsonMessage() throws RFXComException {
109         configuration.enableRubicson = true;
110         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530002000000000000");
111     }
112
113     @Test
114     public void testAEBlyssMessage() throws RFXComException {
115         configuration.enableAEBlyss = true;
116         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530001000000000000");
117     }
118
119     @Test
120     public void testBlindsT1T2T3T4Message() throws RFXComException {
121         configuration.enableBlindsT1T2T3T4 = true;
122         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000800000000000");
123     }
124
125     @Test
126     public void testBlindsT0Message() throws RFXComException {
127         configuration.enableBlindsT0 = true;
128         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000400000000000");
129     }
130
131     @Test
132     public void testProGuardMessage() throws RFXComException {
133         configuration.enableProGuard = true;
134         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000200000000000");
135     }
136
137     // @Test
138     // public void testFS20PacketsMessage() throws RFXComException {
139     // configuration.enableFS20Packets = true;
140     // testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000100000000000");
141     // }
142
143     @Test
144     public void testLaCrosseMessage() throws RFXComException {
145         configuration.enableLaCrosse = true;
146         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000080000000000");
147     }
148
149     @Test
150     public void testHidekiUPMMessage() throws RFXComException {
151         configuration.enableHidekiUPM = true;
152         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000040000000000");
153     }
154
155     @Test
156     public void testLightwaverRFMessage() throws RFXComException {
157         configuration.enableADLightwaveRF = true;
158         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000020000000000");
159     }
160
161     @Test
162     public void testMertikMessage() throws RFXComException {
163         configuration.enableMertik = true;
164         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000010000000000");
165     }
166
167     @Test
168     public void testVisionicMessage() throws RFXComException {
169         configuration.enableVisonic = true;
170         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000008000000000");
171     }
172
173     @Test
174     public void testATIMessage() throws RFXComException {
175         configuration.enableATI = true;
176         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000004000000000");
177     }
178
179     @Test
180     public void testOregonScientificMessage() throws RFXComException {
181         configuration.enableOregonScientific = true;
182         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000002000000000");
183     }
184
185     @Test
186     public void testMeiantechMessage() throws RFXComException {
187         configuration.enableMeiantech = true;
188         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000001000000000");
189     }
190
191     @Test
192     public void testHomeEasyEUMessage() throws RFXComException {
193         configuration.enableHomeEasyEU = true;
194         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000000800000000");
195     }
196
197     @Test
198     public void testACMessage() throws RFXComException {
199         configuration.enableAC = true;
200         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000000400000000");
201     }
202
203     @Test
204     public void testARCMessage() throws RFXComException {
205         configuration.enableARC = true;
206         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000000200000000");
207     }
208
209     @Test
210     public void testX10Message() throws RFXComException {
211         configuration.enableX10 = true;
212         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530000000100000000");
213     }
214
215     @Test
216     public void testTransmitPower() throws RFXComException {
217         configuration.transmitPower = 0;
218         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203531200000000000000");
219     }
220
221     @Test
222     public void testPerSDK() throws RFXComException {
223         configuration.enableUndecoded = true;
224         configuration.enableLaCrosse = true;
225         configuration.enableOregonScientific = true;
226         configuration.enableAC = true;
227         configuration.enableARC = true;
228         configuration.enableX10 = true;
229         testMessage(_433_92MHZ_TRANSCEIVER, configuration, "0D00000203530080082700000000");
230     }
231 }