2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.wifiled.handler;
15 import org.openhab.core.library.types.HSBType;
16 import org.openhab.core.library.types.OnOffType;
17 import org.openhab.core.library.types.PercentType;
19 import java.io.IOException;
22 * Test app for the fading driver.
24 * @author Stefan Endrullis
26 public class WiFiLEDHandlerTestApp {
28 private static AbstractWiFiLEDDriver driver;
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;
35 boolean fadingDriver = false;
37 System.out.println("start");
39 driver = fadingDriver ?
40 new FadingWiFiLEDDriver(ip, port, protocol, 0, 1) :
41 new ClassicWiFiLEDDriver(this, ip, port, protocol);
43 System.out.println("driver created");
47 System.out.println("driver initialized");
50 //testFrequentStateChanges();
55 private static void testStateChanges() throws IOException, InterruptedException {
56 driver.setPower(OnOffType.OFF);
58 System.out.println("off");
62 driver.setPower(OnOffType.ON);
63 driver.setWhite(PercentType.HUNDRED);
64 assertState("ON,0,0,0,100");
67 assertState("ON,0,0,0,100");
69 driver.setColor(HSBType.BLUE);
70 assertState("ON,240,100,100,100");
73 assertState("ON,240,100,100,100");
75 driver.setWhite(PercentType.ZERO);
76 assertState("ON,240,100,100,0");
79 assertState("ON,240,100,100,0");
81 driver.setColor(HSBType.GREEN);
82 driver.setWhite(PercentType.ZERO);
83 System.out.println("g: " + driver.getLEDStateDTO());
86 System.out.println("g: " + driver.getLEDStateDTO());
88 driver.setColor(HSBType.RED);
89 driver.setWhite(PercentType.ZERO);
90 System.out.println("r: " + driver.getLEDStateDTO());
93 System.out.println("r: " + driver.getLEDStateDTO());
95 driver.setColor(HSBType.fromRGB(255, 32, 0));
96 driver.setWhite(new PercentType(14));
97 System.out.println("c: " + driver.getLEDStateDTO());
100 System.out.println("c: " + driver.getLEDStateDTO());
102 driver.setPower(OnOffType.OFF);
103 System.out.println("o: " + driver.getLEDStateDTO());
106 System.out.println("o: " + driver.getLEDStateDTO());
109 private static void testFrequentStateChanges() throws IOException, InterruptedException {
110 driver.setPower(OnOffType.ON);
111 driver.setWhite(PercentType.ZERO);
113 for (int i = 0; i < 100; i++) {
114 driver.setColor(HSBType.BLUE);
116 driver.setColor(HSBType.RED);
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());