From b988e770ad5296f6332d3263c52950a67a4f8cdc Mon Sep 17 00:00:00 2001 From: David Pace Date: Sun, 20 Nov 2022 22:12:49 +0100 Subject: [PATCH] [boschshc] Support smart light bulbs (#13725) * [boschshc] Support smart light bulbs (#13707) * add thing type definition for smart bulbs using system channels * add constants for thing type and channels * implement and register handler * implement binary switch service (to switch on/off) * implement multi-level switch service (allows to get/set brightness from 0-100%) * implement service to get and set colors * add unit tests for handler and state classes - update documentation Signed-off-by: David Pace --- .../org.openhab.binding.boschshc/README.md | 13 ++ .../devices/BoschSHCBindingConstants.java | 5 +- .../devices/BoschSHCHandlerFactory.java | 4 +- .../devices/smartbulb/SmartBulbHandler.java | 117 ++++++++++++++ .../binaryswitch/BinarySwitchService.java | 31 ++++ .../dto/BinarySwitchServiceState.java | 36 +++++ .../HSBColorActuatorService.java | 31 ++++ .../dto/ColorTemperatureRange.java | 24 +++ .../dto/HSBColorActuatorServiceState.java | 51 ++++++ .../MultiLevelSwitchService.java | 33 ++++ .../dto/MultiLevelSwitchServiceState.java | 38 +++++ .../resources/OH-INF/i18n/boschshc.properties | 42 ++++- .../resources/OH-INF/thing/thing-types.xml | 18 +++ .../smartbulb/SmartBulbHandlerTest.java | 146 ++++++++++++++++++ .../dto/BinarySwitchServiceStateTest.java | 35 +++++ .../dto/HSBColorActuatorServiceStateTest.java | 34 ++++ .../dto/MultiLevelSwitchServiceStateTest.java | 34 ++++ 17 files changed, 689 insertions(+), 3 deletions(-) create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/smartbulb/SmartBulbHandler.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/binaryswitch/BinarySwitchService.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/binaryswitch/dto/BinarySwitchServiceState.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/HSBColorActuatorService.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/dto/ColorTemperatureRange.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/dto/HSBColorActuatorServiceState.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/multilevelswitch/MultiLevelSwitchService.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/multilevelswitch/dto/MultiLevelSwitchServiceState.java create mode 100644 bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/smartbulb/SmartBulbHandlerTest.java create mode 100644 bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/binaryswitch/dto/BinarySwitchServiceStateTest.java create mode 100644 bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/hsbcoloractuator/dto/HSBColorActuatorServiceStateTest.java create mode 100644 bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/multilevelswitch/dto/MultiLevelSwitchServiceStateTest.java diff --git a/bundles/org.openhab.binding.boschshc/README.md b/bundles/org.openhab.binding.boschshc/README.md index f5ba3b26141c4..774c54fe301d5 100644 --- a/bundles/org.openhab.binding.boschshc/README.md +++ b/bundles/org.openhab.binding.boschshc/README.md @@ -16,6 +16,7 @@ Binding for the Bosch Smart Home. - [Security Camera 360](#security-camera-360) - [Security Camera Eyes](#security-camera-eyes) - [Intrusion Detection System](#intrusion-detection-system) + - [Smart Bulb](#smart-bulb) - [Limitations](#limitations) - [Discovery](#discovery) - [Bridge Configuration](#bridge-configuration) @@ -178,6 +179,18 @@ Allows to retrieve notifications in case of intrusions. The system can be armed | disarm-action | Switch | ☑ | Disarms the intrusion detection system when an ON command is received. | | mute-action | Switch | ☑ | Mutes the alarm when an ON command is received. | +### Smart Bulb + +A smart bulb connected to the bridge via Zigbee such as a Ledvance Smart+ bulb. + +**Thing Type ID**: `smart-bulb` + +| Channel Type ID | Item Type | Writable | Description | +| ----------------| --------- | :------: | -------------------------------------------------------------- | +| power-switch | Switch | ☑ | Switches the light on or off. | +| brightness | Dimmer | ☑ | Regulates the brightness on a percentage scale from 0 to 100%. | +| color | Color | ☑ | The color of the emitted light. | + ## Limitations - Discovery of Things 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..cf088022076d5 --- /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 OnOffType.from(on); + } +} 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/i18n/boschshc.properties b/bundles/org.openhab.binding.boschshc/src/main/resources/OH-INF/i18n/boschshc.properties index e79a723060cd0..a634c7e3e0020 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/resources/OH-INF/i18n/boschshc.properties +++ b/bundles/org.openhab.binding.boschshc/src/main/resources/OH-INF/i18n/boschshc.properties @@ -9,15 +9,25 @@ thing-type.boschshc.climate-control.label = Climate Control thing-type.boschshc.climate-control.description = This is a virtual device which is automatically created for all rooms that have thermostats in it. thing-type.boschshc.in-wall-switch.label = In-wall Switch thing-type.boschshc.in-wall-switch.description = A simple light control. +thing-type.boschshc.intrusion-detection-system.label = Intrusion Detection System +thing-type.boschshc.intrusion-detection-system.description = Allows to retrieve and control the state of the intrusion detection alarm system. thing-type.boschshc.motion-detector.label = Motion Detector thing-type.boschshc.motion-detector.description = Detects every movement through an intelligent combination of passive infra-red technology and an additional temperature sensor. +thing-type.boschshc.security-camera-360.label = Security Camera 360 +thing-type.boschshc.security-camera-360.description = Indoor security camera with 360° view and motion detection. +thing-type.boschshc.security-camera-eyes.label = Security Camera Eyes +thing-type.boschshc.security-camera-eyes.description = Outdoor security camera with motion detection and light. thing-type.boschshc.shc.label = Smart Home Controller thing-type.boschshc.shc.description = The Bosch Smart Home Bridge representing the Bosch Smart Home Controller. thing-type.boschshc.shutter-control.label = Shutter Control thing-type.boschshc.shutter-control.description = Control of your shutter to take any position you desire. +thing-type.boschshc.smart-bulb.label = Smart Bulb +thing-type.boschshc.smart-bulb.description = A smart bulb connected via Zigbee. +thing-type.boschshc.smart-plug-compact.label = Compact Smart Plug +thing-type.boschshc.smart-plug-compact.description = A compact smart plug with energy monitoring capabilities. thing-type.boschshc.thermostat.label = Thermostat thing-type.boschshc.thermostat.description = Radiator thermostat -thing-type.boschshc.twinguard.label = TwinGuard +thing-type.boschshc.twinguard.label = Twinguard thing-type.boschshc.twinguard.description = The Twinguard smoke detector warns you in case of fire and constantly monitors the air. thing-type.boschshc.wall-thermostat.label = Wall Thermostat thing-type.boschshc.wall-thermostat.description = Display of the current room temperature as well as the relative humidity in the room. @@ -35,8 +45,28 @@ thing-type.config.boschshc.device.id.description = Unique ID of the device. # channel types +channel-type.boschshc.active-configuration-profile.label = Active Configuration Profile +channel-type.boschshc.active-configuration-profile.description = The name of the active configuration profile used for the intrusion detection system. channel-type.boschshc.air-description.label = Description channel-type.boschshc.air-description.description = Overall description of the air quality. +channel-type.boschshc.alarm-state.label = Alarm State +channel-type.boschshc.alarm-state.description = The alarm state of the intrusion detection system. Possible values are ALARM_OFF, PRE_ALARM, ALARM_ON, ALARM_MUTED and UNKNOWN. +channel-type.boschshc.alarm-state.state.option.ALARM_OFF = No alarm +channel-type.boschshc.alarm-state.state.option.PRE_ALARM = Alarm is about to go off +channel-type.boschshc.alarm-state.state.option.ALARM_ON = Alarm was triggered +channel-type.boschshc.alarm-state.state.option.ALARM_MUTED = Alarm is muted +channel-type.boschshc.alarm-state.state.option.UNKNOWN = Alarm status is unknown +channel-type.boschshc.arm-action.label = Arm Action +channel-type.boschshc.arm-action.description = Arms the intrusion detection system using the given profile ID. +channel-type.boschshc.arming-state.label = Arming State +channel-type.boschshc.arming-state.description = The arming state of the intrusion detection system. Possible values are SYSTEM_ARMING, SYSTEM_ARMED and SYSTEM_DISARMED. This channel is read-only. Use the arm-action and disarm-action channels to arm and disarm the system. +channel-type.boschshc.arming-state.state.option.SYSTEM_ARMING = System is currently arming +channel-type.boschshc.arming-state.state.option.SYSTEM_ARMED = System is armed +channel-type.boschshc.arming-state.state.option.SYSTEM_DISARMED = System is disarmed +channel-type.boschshc.camera-notification.label = Camera Notifications +channel-type.boschshc.camera-notification.description = Enables or disables notifications for the camera. +channel-type.boschshc.camera-notification.state.option.ENABLED = Enable notifications +channel-type.boschshc.camera-notification.state.option.DISABLED = Disable notifications channel-type.boschshc.child-lock.label = Child Lock channel-type.boschshc.child-lock.description = Indicates if it is possible to set the desired temperature on the device. channel-type.boschshc.combined-rating.label = Combined Rating @@ -46,6 +76,8 @@ channel-type.boschshc.combined-rating.state.option.MEDIUM = Medium Quality channel-type.boschshc.combined-rating.state.option.BAD = Bad Quality channel-type.boschshc.contact.label = Window/Door contact channel-type.boschshc.contact.description = A window and door contact. +channel-type.boschshc.disarm-action.label = Disarm Action +channel-type.boschshc.disarm-action.description = Disarms the intrusion detection system when an ON command is received. channel-type.boschshc.energy-consumption.label = Energy consumption (Wh) channel-type.boschshc.energy-consumption.description = Energy consumption of the device. channel-type.boschshc.humidity-rating.label = Humidity Rating @@ -59,14 +91,22 @@ channel-type.boschshc.latest-motion.label = Latest motion channel-type.boschshc.latest-motion.description = Timestamp of the latest motion. channel-type.boschshc.level.label = Level channel-type.boschshc.level.description = Current open ratio (0 to 100). +channel-type.boschshc.mute-action.label = Mute Action +channel-type.boschshc.mute-action.description = Mutes the alarm when an ON command is received. channel-type.boschshc.power-consumption.label = Power consumption (W) channel-type.boschshc.power-consumption.description = Current power consumption of the device. +channel-type.boschshc.privacy-mode.label = Privacy Mode +channel-type.boschshc.privacy-mode.description = If privacy mode is enabled, the camera is disabled and vice versa. +channel-type.boschshc.privacy-mode.state.option.ENABLED = Privacy mode enabled (camera disabled) +channel-type.boschshc.privacy-mode.state.option.DISABLED = Privacy mode disabled (camera enabled) channel-type.boschshc.purity-rating.label = Purity Rating channel-type.boschshc.purity-rating.description = Rating of the air purity. channel-type.boschshc.purity.label = Purity channel-type.boschshc.purity.description = Purity of the air. A higher value indicates a higher pollution. channel-type.boschshc.setpoint-temperature.label = Setpoint Temperature channel-type.boschshc.setpoint-temperature.description = Desired temperature. +channel-type.boschshc.system-availability.label = System Availability +channel-type.boschshc.system-availability.description = Indicates whether the intrusion detection system is available. channel-type.boschshc.temperature-rating.label = Temperature Rating channel-type.boschshc.temperature-rating.description = Rating of the currently measured temperature. channel-type.boschshc.temperature-rating.state.option.GOOD = Good Temperature 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()); + } +}