]> git.basschouten.com Git - openhab-addons.git/blob
4e69f6790eb0da87d5a37022564352db2eedba3d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.Assert.*;
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.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("Brightness channel as OnOffType type should be handled",
46                 device.handleCommand(CHANNEL_UID_BRIGHTNESS, OnOffType.ON));
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("Brightness channel with percentage 0 should be handled",
54                 device.handleCommand(CHANNEL_UID_BRIGHTNESS, PercentType.ZERO));
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("Brightness channel should be handled",
62                 device.handleCommand(CHANNEL_UID_BRIGHTNESS, new PercentType(17)));
63     }
64
65     @Test
66     public void testUpdateChannelSwitch() throws IOException {
67         deviceState = new DeviceState(ModelTestUtil.readJson("hs220_get_sysinfo_response_off"));
68
69         assertSame("Dimmer device should be off", OnOffType.OFF,
70                 ((PercentType) device.updateChannel(CHANNEL_UID_BRIGHTNESS, deviceState)).as(OnOffType.class));
71     }
72
73     @Test
74     public void testUpdateChannelBrightness() {
75         assertEquals("Dimmer brightness should be set", BRIGHTNESS_VALUE,
76                 device.updateChannel(CHANNEL_UID_BRIGHTNESS, deviceState));
77     }
78
79     @Test
80     public void testUpdateChannelOther() {
81         assertSame("Unknown channel should return UNDEF", UnDefType.UNDEF,
82                 device.updateChannel(CHANNEL_UID_OTHER, deviceState));
83     }
84 }