]> git.basschouten.com Git - openhab-addons.git/blob
ac22b1f6c4368d758ec00001f59996a4acd63808
[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.wifiled.handler;
14
15 import org.openhab.core.library.types.HSBType;
16 import org.openhab.core.library.types.OnOffType;
17 import org.openhab.core.library.types.PercentType;
18
19 import java.io.IOException;
20
21 /**
22  * Test app for the fading driver.
23  *
24  * @author Stefan Endrullis
25  */
26 public class WiFiLEDHandlerTestApp {
27
28         private static AbstractWiFiLEDDriver driver;
29
30         public static void main(String[] args) throws IOException, InterruptedException {
31                 String ip = "192.168.178.91";
32                 Integer port = AbstractWiFiLEDDriver.DEFAULT_PORT;
33                 AbstractWiFiLEDDriver.Protocol protocol = AbstractWiFiLEDDriver.Protocol.LD686;
34
35                 boolean fadingDriver = false;
36
37                 System.out.println("start");
38
39                 driver = fadingDriver ?
40                                 new FadingWiFiLEDDriver(ip, port, protocol, 0, 1) :
41                                 new ClassicWiFiLEDDriver(this, ip, port, protocol);
42
43                 System.out.println("driver created");
44
45                 driver.init();
46
47                 System.out.println("driver initialized");
48
49                 testStateChanges();
50                 //testFrequentStateChanges();
51
52                 System.exit(0);
53         }
54
55         private static void testStateChanges() throws IOException, InterruptedException {
56                 driver.setPower(OnOffType.OFF);
57
58                 System.out.println("off");
59
60                 Thread.sleep(500);
61
62                 driver.setPower(OnOffType.ON);
63                 driver.setWhite(PercentType.HUNDRED);
64                 assertState("ON,0,0,0,100");
65
66                 Thread.sleep(4000);
67                 assertState("ON,0,0,0,100");
68
69                 driver.setColor(HSBType.BLUE);
70                 assertState("ON,240,100,100,100");
71
72                 Thread.sleep(4000);
73                 assertState("ON,240,100,100,100");
74
75                 driver.setWhite(PercentType.ZERO);
76                 assertState("ON,240,100,100,0");
77
78                 Thread.sleep(4000);
79                 assertState("ON,240,100,100,0");
80
81                 driver.setColor(HSBType.GREEN);
82                 driver.setWhite(PercentType.ZERO);
83                 System.out.println("g: " + driver.getLEDStateDTO());
84
85                 Thread.sleep(4000);
86                 System.out.println("g: " + driver.getLEDStateDTO());
87
88                 driver.setColor(HSBType.RED);
89                 driver.setWhite(PercentType.ZERO);
90                 System.out.println("r: " + driver.getLEDStateDTO());
91
92                 Thread.sleep(4000);
93                 System.out.println("r: " + driver.getLEDStateDTO());
94
95                 driver.setColor(HSBType.fromRGB(255, 32, 0));
96                 driver.setWhite(new PercentType(14));
97                 System.out.println("c: " + driver.getLEDStateDTO());
98
99                 Thread.sleep(4000);
100                 System.out.println("c: " + driver.getLEDStateDTO());
101
102                 driver.setPower(OnOffType.OFF);
103                 System.out.println("o: " + driver.getLEDStateDTO());
104
105                 Thread.sleep(4000);
106                 System.out.println("o: " + driver.getLEDStateDTO());
107         }
108
109         private static void testFrequentStateChanges() throws IOException, InterruptedException {
110                 driver.setPower(OnOffType.ON);
111                 driver.setWhite(PercentType.ZERO);
112
113                 for (int i = 0; i < 100; i++) {
114                         driver.setColor(HSBType.BLUE);
115                         Thread.sleep(100);
116                         driver.setColor(HSBType.RED);
117                         Thread.sleep(100);
118                 }
119         }
120
121         private static void assertState(String state) throws IOException {
122                 if (!driver.getLEDStateDTO().toString().equals(state + " [0,100]")) {
123                         //throw new RuntimeException("Expected: " + state + " [0,100]; actually: " + driver.getLEDStateDTO().toString());
124                 }
125         }
126
127 }