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.*;
18 import java.io.IOException;
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;
28 * Test class for {@link DimmerDevice}.
30 * @author Hilbrand Bouwkamp - Initial contribution
33 public class DimmerDeviceTest extends DeviceTestBase<DimmerDevice> {
35 private static final PercentType BRIGHTNESS_VALUE = new PercentType(50);
37 public DimmerDeviceTest() throws IOException {
38 super(new DimmerDevice(), "hs220_get_sysinfo_response_on");
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));
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));
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)));
66 public void testUpdateChannelSwitch() throws IOException {
67 deviceState = new DeviceState(ModelTestUtil.readJson("hs220_get_sysinfo_response_off"));
69 assertSame("Dimmer device should be off", OnOffType.OFF,
70 ((PercentType) device.updateChannel(CHANNEL_UID_BRIGHTNESS, deviceState)).as(OnOffType.class));
74 public void testUpdateChannelBrightness() {
75 assertEquals("Dimmer brightness should be set", BRIGHTNESS_VALUE,
76 device.updateChannel(CHANNEL_UID_BRIGHTNESS, deviceState));
80 public void testUpdateChannelOther() {
81 assertSame("Unknown channel should return UNDEF", UnDefType.UNDEF,
82 device.updateChannel(CHANNEL_UID_OTHER, deviceState));