2 * Copyright (c) 2010-2020 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.tplinksmarthome.internal.device;
15 import static org.junit.Assert.*;
16 import static org.openhab.binding.tplinksmarthome.internal.ChannelUIDConstants.*;
17 import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.*;
18 import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeThingType.LB130;
20 import java.io.IOException;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.junit.Test;
24 import org.openhab.binding.tplinksmarthome.internal.model.ModelTestUtil;
25 import org.openhab.core.library.types.DecimalType;
26 import org.openhab.core.library.types.HSBType;
27 import org.openhab.core.library.types.OnOffType;
28 import org.openhab.core.library.types.PercentType;
29 import org.openhab.core.types.UnDefType;
32 * Test class for {@link BulbDevice} class.
34 * @author Hilbrand Bouwkamp - Initial contribution
37 public class BulbDeviceTest extends DeviceTestBase<BulbDevice> {
39 private static final String DEVICE_OFF = "bulb_get_sysinfo_response_off";
41 public BulbDeviceTest() throws IOException {
42 super(new BulbDevice(LB130.thingTypeUID(), COLOR_TEMPERATURE_2_MIN, COLOR_TEMPERATURE_2_MAX),
43 "bulb_get_sysinfo_response_on");
47 public void setUp() throws IOException {
49 setSocketReturnAssert("bulb_transition_light_state_response");
53 public void testHandleCommandBrightness() throws IOException {
54 assertInput("bulb_transition_light_state_brightness");
55 assertTrue("Brightness channel should be handled",
56 device.handleCommand(CHANNEL_UID_BRIGHTNESS, new PercentType(33)));
60 public void testHandleCommandBrightnessOnOff() throws IOException {
61 assertInput("bulb_transition_light_state_on");
62 assertTrue("Brightness channel with OnOff state should be handled",
63 device.handleCommand(CHANNEL_UID_BRIGHTNESS, OnOffType.ON));
67 public void testHandleCommandColor() throws IOException {
68 assertInput("bulb_transition_light_state_color");
69 assertTrue("Color channel should be handled", device.handleCommand(CHANNEL_UID_COLOR, new HSBType("55,44,33")));
72 public void testHandleCommandColorBrightness() throws IOException {
73 assertInput("bulb_transition_light_state_brightness");
74 assertTrue("Color channel with Percentage state (=brightness) should be handled",
75 device.handleCommand(CHANNEL_UID_COLOR, new PercentType(33)));
78 public void testHandleCommandColorOnOff() throws IOException {
79 assertInput("bulb_transition_light_state_on");
80 assertTrue("Color channel with OnOff state should be handled",
81 device.handleCommand(CHANNEL_UID_COLOR, OnOffType.ON));
85 public void testHandleCommandColorTemperature() throws IOException {
86 assertInput("bulb_transition_light_state_color_temp");
87 assertTrue("Color temperature channel should be handled",
88 device.handleCommand(CHANNEL_UID_COLOR_TEMPERATURE, new PercentType(40)));
92 public void testHandleCommandColorTemperatureAbs() throws IOException {
93 assertInput("bulb_transition_light_state_color_temp");
94 assertTrue("Color temperature channel should be handled",
95 device.handleCommand(CHANNEL_UID_COLOR_TEMPERATURE_ABS, new DecimalType(5100)));
99 public void testHandleCommandColorTemperatureOnOff() throws IOException {
100 assertInput("bulb_transition_light_state_on");
101 assertTrue("Color temperature channel with OnOff state should be handled",
102 device.handleCommand(CHANNEL_UID_COLOR_TEMPERATURE, OnOffType.ON));
106 public void testHandleCommandSwitch() throws IOException {
107 assertInput("bulb_transition_light_state_on");
108 assertTrue("Switch channel should be handled", device.handleCommand(CHANNEL_UID_SWITCH, OnOffType.ON));
112 public void testUpdateChannelBrightnessOn() {
113 assertEquals("Brightness should be on", new PercentType(92),
114 device.updateChannel(CHANNEL_UID_BRIGHTNESS, deviceState));
118 public void testUpdateChannelBrightnessOff() throws IOException {
119 deviceState = new DeviceState(ModelTestUtil.readJson(DEVICE_OFF));
120 assertEquals("Brightness should be off", PercentType.ZERO,
121 device.updateChannel(CHANNEL_UID_BRIGHTNESS, deviceState));
125 public void testUpdateChannelColorOn() {
126 assertEquals("Color should be on", new HSBType("7,44,92"),
127 device.updateChannel(CHANNEL_UID_COLOR, deviceState));
131 public void testUpdateChannelColorOff() throws IOException {
132 deviceState = new DeviceState(ModelTestUtil.readJson(DEVICE_OFF));
133 assertEquals("Color should be off", new HSBType("7,44,0"),
134 device.updateChannel(CHANNEL_UID_COLOR, deviceState));
138 public void testUpdateChannelSwitchOn() {
139 assertSame("Switch should be on", OnOffType.ON, device.updateChannel(CHANNEL_UID_SWITCH, deviceState));
143 public void testUpdateChannelSwitchOff() throws IOException {
144 deviceState = new DeviceState(ModelTestUtil.readJson(DEVICE_OFF));
145 assertSame("Switch should be off", OnOffType.OFF, device.updateChannel(CHANNEL_UID_SWITCH, deviceState));
149 public void testUpdateChannelColorTemperature() {
150 assertEquals("Color temperature should be set", new PercentType(2),
151 device.updateChannel(CHANNEL_UID_COLOR_TEMPERATURE, deviceState));
155 public void testUpdateChannelColorTemperatureAbs() {
156 assertEquals("Color temperature should be set", new DecimalType(2630),
157 device.updateChannel(CHANNEL_UID_COLOR_TEMPERATURE_ABS, deviceState));
161 public void testUpdateChannelOther() {
162 assertSame("Unknown channel should return UNDEF", UnDefType.UNDEF,
163 device.updateChannel(CHANNEL_UID_OTHER, deviceState));
167 public void testUpdateChannelPower() {
168 assertEquals("Power values should be set", new DecimalType(10.8),
169 device.updateChannel(CHANNEL_UID_ENERGY_POWER, deviceState));