diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCBindingConstants.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCBindingConstants.java index 56f61ce5c108d..4425b76909b76 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCBindingConstants.java +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCBindingConstants.java @@ -22,7 +22,7 @@ * @author Stefan Kästle - Initial contribution * @author Christian Oeing - added Shutter Control, ThermostatHandler * @author Christian Oeing - Added WallThermostatHandler - * @author David Pace - Added cameras and intrusion detection system + * @author David Pace - Added cameras, intrusion detection system, smart plugs, battery state support and smart bulbs */ @NonNullByDefault public class BoschSHCBindingConstants { @@ -45,6 +45,7 @@ public class BoschSHCBindingConstants { public static final ThingTypeUID THING_TYPE_INTRUSION_DETECTION_SYSTEM = new ThingTypeUID(BINDING_ID, "intrusion-detection-system"); public static final ThingTypeUID THING_TYPE_SMART_PLUG_COMPACT = new ThingTypeUID(BINDING_ID, "smart-plug-compact"); + public static final ThingTypeUID THING_TYPE_SMART_BULB = new ThingTypeUID(BINDING_ID, "smart-bulb"); // List of all Channel IDs // Auto-generated from thing-types.xml via script, don't modify @@ -76,6 +77,8 @@ public class BoschSHCBindingConstants { public static final String CHANNEL_MUTE_ACTION = "mute-action"; public static final String CHANNEL_BATTERY_LEVEL = "battery-level"; public static final String CHANNEL_LOW_BATTERY = "low-battery"; + public static final String CHANNEL_COLOR = "color"; + public static final String CHANNEL_BRIGHTNESS = "brightness"; // static device/service names public static final String SERVICE_INTRUSION_DETECTION = "intrusionDetectionSystem"; diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCHandlerFactory.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCHandlerFactory.java index 81dffc59f60c5..1de7728829eb6 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCHandlerFactory.java +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCHandlerFactory.java @@ -28,6 +28,7 @@ import org.openhab.binding.boschshc.internal.devices.motiondetector.MotionDetectorHandler; import org.openhab.binding.boschshc.internal.devices.plug.PlugHandler; import org.openhab.binding.boschshc.internal.devices.shuttercontrol.ShutterControlHandler; +import org.openhab.binding.boschshc.internal.devices.smartbulb.SmartBulbHandler; import org.openhab.binding.boschshc.internal.devices.thermostat.ThermostatHandler; import org.openhab.binding.boschshc.internal.devices.twinguard.TwinguardHandler; import org.openhab.binding.boschshc.internal.devices.wallthermostat.WallThermostatHandler; @@ -77,7 +78,8 @@ public ThingTypeHandlerMapping(ThingTypeUID thingTypeUID, Function { + + public BinarySwitchService() { + super("BinarySwitch", BinarySwitchServiceState.class); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/binaryswitch/dto/BinarySwitchServiceState.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/binaryswitch/dto/BinarySwitchServiceState.java new file mode 100644 index 0000000000000..b096ff32c4ea2 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/binaryswitch/dto/BinarySwitchServiceState.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.boschshc.internal.services.binaryswitch.dto; + +import org.eclipse.jdt.annotation.NonNull; +import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState; +import org.openhab.core.library.types.OnOffType; + +/** + * State for devices and services that can be turned on and off. + * + * @author David Pace - Initial contribution + * + */ +public class BinarySwitchServiceState extends BoschSHCServiceState { + + public BinarySwitchServiceState() { + super("binarySwitchState"); + } + + public boolean on; + + public @NonNull OnOffType toOnOffType() { + return on ? OnOffType.ON : OnOffType.OFF; + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/HSBColorActuatorService.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/HSBColorActuatorService.java new file mode 100644 index 0000000000000..e16e14025674d --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/HSBColorActuatorService.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.boschshc.internal.services.hsbcoloractuator; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.boschshc.internal.services.BoschSHCService; +import org.openhab.binding.boschshc.internal.services.hsbcoloractuator.dto.HSBColorActuatorServiceState; + +/** + * Service for devices that can emit colored light. + * + * @author David Pace - Initial contribution + * + */ +@NonNullByDefault +public class HSBColorActuatorService extends BoschSHCService { + + public HSBColorActuatorService() { + super("HSBColorActuator", HSBColorActuatorServiceState.class); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/dto/ColorTemperatureRange.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/dto/ColorTemperatureRange.java new file mode 100644 index 0000000000000..223a7e4c79737 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/dto/ColorTemperatureRange.java @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.boschshc.internal.services.hsbcoloractuator.dto; + +/** + * State representing the color temperature range of light bulbs. + * + * @author David Pace - Initial contribution + * + */ +public class ColorTemperatureRange { + public int minCt; + public int maxCt; +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/dto/HSBColorActuatorServiceState.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/dto/HSBColorActuatorServiceState.java new file mode 100644 index 0000000000000..ce67e39dd6e49 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/dto/HSBColorActuatorServiceState.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.boschshc.internal.services.hsbcoloractuator.dto; + +import java.awt.Color; + +import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState; +import org.openhab.core.library.types.HSBType; + +/** + * State representing colors of light bulbs. + * + * @author David Pace - Initial contribution + * + */ +public class HSBColorActuatorServiceState extends BoschSHCServiceState { + + public HSBColorActuatorServiceState() { + super("colorState"); + } + + /** + * RGB value modeled as an sRGB integer value (bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue). + * Alpha is set to the fixed value 255. + */ + public int rgb; + + public String gamut; + + public ColorTemperatureRange colorTemperatureRange; + + /** + * Converts the combined {@link #rgb} value to an openHAB-compliant HSB state. + * + * @return color as {@link HSBType} + */ + public HSBType toHSBType() { + Color color = new Color(rgb); + return HSBType.fromRGB(color.getRed(), color.getGreen(), color.getBlue()); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/multilevelswitch/MultiLevelSwitchService.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/multilevelswitch/MultiLevelSwitchService.java new file mode 100644 index 0000000000000..58f926ab0d2e0 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/multilevelswitch/MultiLevelSwitchService.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.boschshc.internal.services.multilevelswitch; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.boschshc.internal.services.BoschSHCService; +import org.openhab.binding.boschshc.internal.services.multilevelswitch.dto.MultiLevelSwitchServiceState; + +/** + * Service for devices with switches that can have multiple different levels. + *

+ * Example: light bulbs with controllable brightness levels from 0 to 100%. + * + * @author David Pace - Initial contribution + * + */ +@NonNullByDefault +public class MultiLevelSwitchService extends BoschSHCService { + + public MultiLevelSwitchService() { + super("MultiLevelSwitch", MultiLevelSwitchServiceState.class); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/multilevelswitch/dto/MultiLevelSwitchServiceState.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/multilevelswitch/dto/MultiLevelSwitchServiceState.java new file mode 100644 index 0000000000000..1b8fc508255a5 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/multilevelswitch/dto/MultiLevelSwitchServiceState.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.boschshc.internal.services.multilevelswitch.dto; + +import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState; +import org.openhab.core.library.types.PercentType; + +/** + * State for devices with switches that can have multiple different levels. + * + * @author David Pace - Initial contribution + * + */ +public class MultiLevelSwitchServiceState extends BoschSHCServiceState { + + public MultiLevelSwitchServiceState() { + super("multiLevelSwitchState"); + } + + /** + * Represents a percentage level between 0 and 100 + */ + public int level; + + public PercentType toPercentType() { + return new PercentType(level); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.boschshc/src/main/resources/OH-INF/thing/thing-types.xml index 5f3095f76da1e..ab84a6fea0c32 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.boschshc/src/main/resources/OH-INF/thing/thing-types.xml @@ -237,6 +237,24 @@ + + + + + + + A smart bulb connected via Zigbee. + + + + + + + + + + + Switch diff --git a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/smartbulb/SmartBulbHandlerTest.java b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/smartbulb/SmartBulbHandlerTest.java new file mode 100644 index 0000000000000..7d97b8752d8c4 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/smartbulb/SmartBulbHandlerTest.java @@ -0,0 +1,146 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.boschshc.internal.devices.smartbulb; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.*; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.openhab.binding.boschshc.internal.devices.AbstractBoschSHCDeviceHandlerTest; +import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants; +import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException; +import org.openhab.binding.boschshc.internal.services.binaryswitch.dto.BinarySwitchServiceState; +import org.openhab.binding.boschshc.internal.services.hsbcoloractuator.dto.HSBColorActuatorServiceState; +import org.openhab.binding.boschshc.internal.services.multilevelswitch.dto.MultiLevelSwitchServiceState; +import org.openhab.core.library.types.HSBType; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.PercentType; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.ThingTypeUID; +import org.openhab.core.thing.ThingUID; + +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; + +/** + * Unit tests for {@link SmartBulbHandler}. + * + * @author David Pace - Initial contribution + * + */ +public class SmartBulbHandlerTest extends AbstractBoschSHCDeviceHandlerTest { + + @Captor + private ArgumentCaptor binarySwitchServiceStateCaptor; + + @Captor + private ArgumentCaptor multiLevelSwitchServiceStateCaptor; + + @Captor + private ArgumentCaptor hsbColorActuatorServiceStateCaptor; + + @Override + protected SmartBulbHandler createFixture() { + return new SmartBulbHandler(getThing()); + } + + @Override + protected String getDeviceID() { + return "hdm:ZigBee:f0d1b80000f2a3e9"; + } + + @Override + protected ThingTypeUID getThingTypeUID() { + return BoschSHCBindingConstants.THING_TYPE_SMART_BULB; + } + + @Test + public void testHandleCommand_BinarySwitch() + throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException { + + getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_POWER_SWITCH), + OnOffType.ON); + verify(getBridgeHandler()).putState(eq(getDeviceID()), eq("BinarySwitch"), + binarySwitchServiceStateCaptor.capture()); + BinarySwitchServiceState state = binarySwitchServiceStateCaptor.getValue(); + assertTrue(state.on); + + getFixture().handleCommand(new ChannelUID(new ThingUID(getThingTypeUID(), "abcdef"), + BoschSHCBindingConstants.CHANNEL_POWER_SWITCH), OnOffType.OFF); + verify(getBridgeHandler(), times(2)).putState(eq(getDeviceID()), eq("BinarySwitch"), + binarySwitchServiceStateCaptor.capture()); + state = binarySwitchServiceStateCaptor.getValue(); + assertFalse(state.on); + } + + @Test + public void testHandleCommand_MultiLevelSwitch() + throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException { + + getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_BRIGHTNESS), + new PercentType(42)); + verify(getBridgeHandler()).putState(eq(getDeviceID()), eq("MultiLevelSwitch"), + multiLevelSwitchServiceStateCaptor.capture()); + MultiLevelSwitchServiceState state = multiLevelSwitchServiceStateCaptor.getValue(); + assertEquals(42, state.level); + } + + @Test + public void testHandleCommand_HSBColorActuator() + throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException { + + getFixture().handleCommand(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_COLOR), + HSBType.BLUE); + verify(getBridgeHandler()).putState(eq(getDeviceID()), eq("HSBColorActuator"), + hsbColorActuatorServiceStateCaptor.capture()); + HSBColorActuatorServiceState state = hsbColorActuatorServiceStateCaptor.getValue(); + assertEquals(-16776961, state.rgb); + } + + @Test + public void testUpdateChannel_BinarySwitchState() { + JsonElement jsonObject = JsonParser.parseString("{\"@type\":\"binarySwitchState\",\"on\":true}"); + getFixture().processUpdate("BinarySwitch", jsonObject); + verify(getCallback()).stateUpdated( + new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_POWER_SWITCH), OnOffType.ON); + + jsonObject = JsonParser.parseString("{\"@type\":\"binarySwitchState\",\"on\":false}"); + getFixture().processUpdate("BinarySwitch", jsonObject); + verify(getCallback()).stateUpdated( + new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_POWER_SWITCH), OnOffType.OFF); + } + + @Test + public void testUpdateChannel_MultiLevelSwitchState() { + JsonElement jsonObject = JsonParser.parseString("{\"@type\":\"multiLevelSwitchState\",\"level\":16}"); + getFixture().processUpdate("MultiLevelSwitch", jsonObject); + verify(getCallback()).stateUpdated( + new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_BRIGHTNESS), new PercentType(16)); + } + + @Test + public void testUpdateChannel_HSBColorActuatorState() { + JsonElement jsonObject = JsonParser.parseString("{\"colorTemperatureRange\": {\n" + " \"minCt\": 153,\n" + + " \"maxCt\": 526\n" + " },\n" + " \"@type\": \"colorState\",\n" + + " \"gamut\": \"LEDVANCE_GAMUT_A\",\n" + " \"rgb\": -12427}"); + getFixture().processUpdate("HSBColorActuator", jsonObject); + verify(getCallback()).stateUpdated(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_COLOR), + HSBType.fromRGB(255, 207, 117)); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/binaryswitch/dto/BinarySwitchServiceStateTest.java b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/binaryswitch/dto/BinarySwitchServiceStateTest.java new file mode 100644 index 0000000000000..ba9aa85f7ab26 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/binaryswitch/dto/BinarySwitchServiceStateTest.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.boschshc.internal.services.binaryswitch.dto; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.openhab.core.library.types.OnOffType; + +/** + * Unit tests for {@link BinarySwitchServiceState}. + * + * @author David Pace - Initial contribution + * + */ +public class BinarySwitchServiceStateTest { + + @Test + void testToOnOffType() { + BinarySwitchServiceState binarySwitchServiceState = new BinarySwitchServiceState(); + assertEquals(OnOffType.OFF, binarySwitchServiceState.toOnOffType()); + binarySwitchServiceState.on = true; + assertEquals(OnOffType.ON, binarySwitchServiceState.toOnOffType()); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/dto/HSBColorActuatorServiceStateTest.java b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/dto/HSBColorActuatorServiceStateTest.java new file mode 100644 index 0000000000000..d21890306bb42 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/dto/HSBColorActuatorServiceStateTest.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.boschshc.internal.services.hsbcoloractuator.dto; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.openhab.core.library.types.HSBType; + +/** + * Unit tests for {@link HSBColorActuatorServiceState}. + * + * @author David Pace - Initial contribution + * + */ +public class HSBColorActuatorServiceStateTest { + + @Test + void testToHSBType() { + HSBColorActuatorServiceState hsbColorActuatorState = new HSBColorActuatorServiceState(); + hsbColorActuatorState.rgb = -12427; // r = 255, g = 207, b = 117 + assertEquals(HSBType.fromRGB(255, 207, 117), hsbColorActuatorState.toHSBType()); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/multilevelswitch/dto/MultiLevelSwitchServiceStateTest.java b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/multilevelswitch/dto/MultiLevelSwitchServiceStateTest.java new file mode 100644 index 0000000000000..eb920c605b892 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/multilevelswitch/dto/MultiLevelSwitchServiceStateTest.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.boschshc.internal.services.multilevelswitch.dto; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.openhab.core.library.types.PercentType; + +/** + * Unit tests for {@link MultiLevelSwitchServiceState}. + * + * @author David Pace - Initial contribution + * + */ +public class MultiLevelSwitchServiceStateTest { + + @Test + void testToPercentType() { + MultiLevelSwitchServiceState multiLevelSwitchState = new MultiLevelSwitchServiceState(); + multiLevelSwitchState.level = 42; + assertEquals(new PercentType(42), multiLevelSwitchState.toPercentType()); + } +}