2 * Copyright (c) 2010-2024 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.internal.handler;
15 import static org.hamcrest.CoreMatchers.is;
16 import static org.hamcrest.MatcherAssert.assertThat;
18 import org.junit.jupiter.api.Test;
21 * Test for LEDStateDTO
23 * @author Ries van Twisk - Prevent flashes during classic driver color + white updates
25 public class LEDStateDTOTest {
28 public void RGBTest() {
29 for (int r = 0; r < 256 - 3; r = r + 3) {
30 for (int g = 0; g < 256 - 5; g = g + 5) {
31 for (int b = 0; b < 256 - 7; b = b + 7) {
32 LEDStateDTO ledState = LEDStateDTO.valueOf(0, 0, 0, r, g, b, 0, 0);
33 assertThat(ledState.getRGB() & 0xffffff, is(r << 16 | g << 8 | b));
40 public void RGBTest1() {
41 LEDStateDTO ledState = LEDStateDTO.valueOf(0, 0, 0, 0xff, 0xff, 0xff, 0, 0);
42 assertThat(ledState.getRGB() & 0xffffff, is(0xffffff));
46 public void programSpeedtest() {
47 for (int ps = 0; ps < 0x20; ps++) {
48 LEDStateDTO ledState = LEDStateDTO.valueOf(0, 0, ps, 0, 0, 0, 0, 0);
49 assertThat(ledState.getProgramSpeed().intValue(), is((int) Math.round(100.0 - (100.0 / 0x1f * ps))));
54 public void whiteTest() {
55 for (int wt = 0; wt < 256; wt++) {
56 LEDStateDTO ledState = LEDStateDTO.valueOf(0, 0, 0, 0, 0, 0, wt, wt);
57 assertThat((int) Math.round(ledState.getWhite().doubleValue() * 2.55), is(wt));
58 assertThat(255 - (int) Math.round(ledState.getWhite2().doubleValue() * 2.55), is(255 - wt));
63 public void programTest() {
64 for (int p = 0; p < 256; p++) {
65 LEDStateDTO ledState = LEDStateDTO.valueOf(0, p, 0, 0, 0, 0, 0, 0);
66 assertThat(ledState.getProgram().toString(), is(String.valueOf(p)));