]> git.basschouten.com Git - openhab-addons.git/blob
17e5d68a1e5ed6e131df3213d8616656cd7fbf55
[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.miio.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.util.Collections;
18 import java.util.Map;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.miio.internal.basic.ActionConditions;
23 import org.openhab.binding.miio.internal.basic.MiIoDeviceActionCondition;
24
25 import com.google.gson.JsonElement;
26 import com.google.gson.JsonPrimitive;
27
28 /**
29  * Test case for {@link ActionConditions}
30  *
31  * @author Marcel Verpaalen - Initial contribution
32  *
33  */
34 @NonNullByDefault
35 public class ActionConditionTest {
36
37     @Test
38     public void assertBrightnessExisting() {
39         MiIoDeviceActionCondition condition = new MiIoDeviceActionCondition();
40         condition.setName("BrightnessExisting");
41         Map<String, Object> deviceVariables = Collections.emptyMap();
42         JsonElement value = new JsonPrimitive(1);
43         JsonElement resp = ActionConditions.executeAction(condition, deviceVariables, value, null);
44         // dimmed to 1
45         assertNotNull(resp);
46         assertEquals(new JsonPrimitive(1), resp);
47
48         // fully on
49         value = new JsonPrimitive(100);
50         resp = ActionConditions.executeAction(condition, deviceVariables, value, null);
51         assertNotNull(resp);
52         assertEquals(new JsonPrimitive(100), resp);
53
54         // >100
55         value = new JsonPrimitive(200);
56         resp = ActionConditions.executeAction(condition, deviceVariables, value, null);
57         assertNotNull(resp);
58         assertEquals(new JsonPrimitive(100), resp);
59
60         // switched off = invalid brightness
61         value = new JsonPrimitive(0);
62         resp = ActionConditions.executeAction(condition, deviceVariables, value, null);
63         assertNull(resp);
64         assertNotEquals(new JsonPrimitive(0), resp);
65
66         value = new JsonPrimitive(-1);
67         resp = ActionConditions.executeAction(condition, deviceVariables, value, null);
68         assertNull(resp);
69         assertNotEquals(new JsonPrimitive(-1), resp);
70     }
71 }