2 * Copyright (c) 2010-2023 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.jupiter.api.Assertions.*;
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.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;
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(device.handleCommand(CHANNEL_UID_BRIGHTNESS, OnOffType.ON),
46 "Brightness channel as OnOffType type should be handled");
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");
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");
66 public void testUpdateChannelSwitch() throws IOException {
67 deviceState = new DeviceState(ModelTestUtil.readJson("hs220_get_sysinfo_response_off"));
69 assertSame(OnOffType.OFF,
70 ((PercentType) device.updateChannel(CHANNEL_UID_BRIGHTNESS, deviceState)).as(OnOffType.class),
71 "Dimmer device should be off");
75 public void testUpdateChannelBrightness() {
76 assertEquals(BRIGHTNESS_VALUE, device.updateChannel(CHANNEL_UID_BRIGHTNESS, deviceState),
77 "Dimmer brightness should be set");
81 public void testUpdateChannelOther() {
82 assertSame(UnDefType.UNDEF, device.updateChannel(CHANNEL_UID_OTHER, deviceState),
83 "Unknown channel should return UNDEF");