]> git.basschouten.com Git - openhab-addons.git/blob
cfebb296a9ad94ef12ca9e4673670a287f0df7d4
[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.yeelight.internal.lib.device;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.junit.jupiter.api.BeforeEach;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.yeelight.internal.lib.enums.ActiveMode;
20
21 /**
22  * Unit tests for {@link DeviceBase}
23  *
24  * @author Viktor Koop - Initial contribution
25  */
26 public class DeviceBaseTest {
27
28     private DeviceBase deviceBase;
29
30     @BeforeEach
31     public void setUp() {
32         deviceBase = new DeviceBase("myid") {
33         };
34     }
35
36     @Test
37     public void testSetColorTemp() {
38         String json = "{\"method\":\"props\",\"params\":{\"ct\":4013}}";
39         deviceBase.onNotify(json);
40
41         final DeviceStatus deviceStatus = deviceBase.getDeviceStatus();
42         assertEquals(4013, deviceStatus.getCt());
43     }
44
45     @Test
46     public void testSwitchToNightlightMode() {
47         deviceBase.onNotify("{\"method\":\"props\",\"params\":{\"nl_br\":96,\"active_mode\":1,\"active_bright\":96}}");
48         final DeviceStatus deviceStatus = deviceBase.getDeviceStatus();
49
50         assertEquals(ActiveMode.MOONLIGHT_MODE, deviceStatus.getActiveMode());
51     }
52
53     @Test
54     public void testNightlightBrightnessUpdate() {
55         String json = "{\"method\":\"props\",\"params\":{\"nl_br\":61,\"active_bright\":61}}";
56         deviceBase.onNotify(json);
57
58         final DeviceStatus deviceStatus = deviceBase.getDeviceStatus();
59         assertEquals(61, deviceStatus.getBrightness());
60     }
61 }