]> git.basschouten.com Git - openhab-addons.git/blob
42a89cb84344d7758ac0f53e58b5f6bf465486bc
[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.tplinksmarthome.internal.device;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.openhab.binding.tplinksmarthome.internal.ChannelUIDConstants.*;
17
18 import java.io.IOException;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.tplinksmarthome.internal.model.ModelTestUtil;
23 import org.openhab.core.library.types.OnOffType;
24 import org.openhab.core.library.types.PercentType;
25 import org.openhab.core.types.UnDefType;
26
27 /**
28  * Test class for {@link DimmerDevice}.
29  *
30  * @author Hilbrand Bouwkamp - Initial contribution
31  */
32 @NonNullByDefault
33 public class DimmerDeviceTest extends DeviceTestBase<DimmerDevice> {
34
35     private static final PercentType BRIGHTNESS_VALUE = new PercentType(50);
36
37     public DimmerDeviceTest() throws IOException {
38         super(new DimmerDevice(), "hs220_get_sysinfo_response_on");
39     }
40
41     @Test
42     public void testHandleCommandBrightnessOnOff() throws IOException {
43         assertInput("dimmer_set_switch_state_on");
44         setSocketReturnAssert("dimmer_set_switch_state_on");
45         assertTrue(device.handleCommand(CHANNEL_UID_BRIGHTNESS, OnOffType.ON),
46                 "Brightness channel as OnOffType type should be handled");
47     }
48
49     @Test
50     public void testHandleCommandBrightnessZero() throws IOException {
51         assertInput("dimmer_set_switch_state_off");
52         setSocketReturnAssert("dimmer_set_switch_state_response");
53         assertTrue(device.handleCommand(CHANNEL_UID_BRIGHTNESS, PercentType.ZERO),
54                 "Brightness channel with percentage 0 should be handled");
55     }
56
57     @Test
58     public void testHandleCommandBrightness() throws IOException {
59         assertInput("dimmer_set_brightness", "dimmer_set_switch_state_on");
60         setSocketReturnAssert("dimmer_set_brightness_response", "dimmer_set_switch_state_on");
61         assertTrue(device.handleCommand(CHANNEL_UID_BRIGHTNESS, new PercentType(17)),
62                 "Brightness channel should be handled");
63     }
64
65     @Test
66     public void testUpdateChannelSwitch() throws IOException {
67         deviceState = new DeviceState(ModelTestUtil.readJson("hs220_get_sysinfo_response_off"));
68
69         assertSame(OnOffType.OFF,
70                 ((PercentType) device.updateChannel(CHANNEL_UID_BRIGHTNESS, deviceState)).as(OnOffType.class),
71                 "Dimmer device should be off");
72     }
73
74     @Test
75     public void testUpdateChannelBrightness() {
76         assertEquals(BRIGHTNESS_VALUE, device.updateChannel(CHANNEL_UID_BRIGHTNESS, deviceState),
77                 "Dimmer brightness should be set");
78     }
79
80     @Test
81     public void testUpdateChannelOther() {
82         assertSame(UnDefType.UNDEF, device.updateChannel(CHANNEL_UID_OTHER, deviceState),
83                 "Unknown channel should return UNDEF");
84     }
85 }