From e335bcb55e630896f6350a1cf677131a6469d5d0 Mon Sep 17 00:00:00 2001 From: David Pace Date: Mon, 18 Dec 2023 23:14:03 +0100 Subject: [PATCH] [boschshc] Support for Door/Window Sensor II * add new thing type for Door/Window Sensor II * add channel types for bypass state and communication quality * add handler extending the basic Door/Window Sensor handler * add service implementations * register handler in discovery service * add unit tests * re-generate i18n properties file * add documentation closes #15954 Signed-off-by: David Pace --- .../org.openhab.binding.boschshc/README.md | 15 +++ .../devices/BoschSHCBindingConstants.java | 3 + .../devices/BoschSHCHandlerFactory.java | 2 + .../windowcontact/WindowContact2Handler.java | 58 +++++++++ .../discovery/ThingDiscoveryService.java | 10 +- .../services/bypass/BypassService.java | 31 +++++ .../bypass/dto/BypassConfiguration.java | 38 ++++++ .../bypass/dto/BypassServiceState.java | 46 +++++++ .../services/bypass/dto/BypassState.java | 25 ++++ .../CommunicationQualityService.java | 31 +++++ .../dto/CommunicationQualityServiceState.java | 39 ++++++ .../dto/CommunicationQualityState.java | 27 +++++ .../resources/OH-INF/i18n/boschshc.properties | 16 +++ .../resources/OH-INF/thing/thing-types.xml | 48 ++++++++ .../WindowContact2HandlerTest.java | 113 ++++++++++++++++++ 15 files changed, 498 insertions(+), 4 deletions(-) create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/windowcontact/WindowContact2Handler.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/BypassService.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassConfiguration.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassServiceState.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassState.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/CommunicationQualityService.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/dto/CommunicationQualityServiceState.java create mode 100644 bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/dto/CommunicationQualityState.java create mode 100644 bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/windowcontact/WindowContact2HandlerTest.java diff --git a/bundles/org.openhab.binding.boschshc/README.md b/bundles/org.openhab.binding.boschshc/README.md index 4b75bb23c2201..42d74276d5909 100644 --- a/bundles/org.openhab.binding.boschshc/README.md +++ b/bundles/org.openhab.binding.boschshc/README.md @@ -9,6 +9,7 @@ Binding for the Bosch Smart Home. - [Compact Smart Plug](#compact-smart-plug) - [Twinguard Smoke Detector](#twinguard-smoke-detector) - [Door/Window Contact](#door-window-contact) + - [Door/Window Contact II](#door-window-contact-ii) - [Motion Detector](#motion-detector) - [Shutter Control](#shutter-control) - [Thermostat](#thermostat) @@ -96,6 +97,20 @@ Detects open windows and doors. | battery-level | Number | ☐ | Current battery level percentage as integer number. Bosch-specific battery levels are mapped to numbers as follows: `OK`: 100, `LOW_BATTERY`: 10, `CRITICAL_LOW`: 1, `CRITICALLY_LOW_BATTERY`: 1, `NOT_AVAILABLE`: `UNDEF`. | | low-battery | Switch | ☐ | Indicates whether the battery is low (`ON`) or OK (`OFF`). | +### Door/Window Contact II + +Detects open windows and doors and features an additional button. + +**Thing Type ID**: `window-contact` + +| Channel Type ID | Item Type | Writable | Description | +| --------------- | --------- | :------: | ---------------------------- | +| contact | Contact | ☐ | Contact state of the device. | +| battery-level | Number | ☐ | Current battery level percentage as integer number. Bosch-specific battery levels are mapped to numbers as follows: `OK`: 100, `LOW_BATTERY`: 10, `CRITICAL_LOW`: 1, `CRITICALLY_LOW_BATTERY`: 1, `NOT_AVAILABLE`: `UNDEF`. | +| low-battery | Switch | ☐ | Indicates whether the battery is low (`ON`) or OK (`OFF`). | +| bypass | String | ☐ | Bypass state of the device. Possible values are `BYPASS_INACTIVE`,`BYPASS_ACTIVE` and `UNKNOWN`. | +| communication-quality | String | ☐ | Communication quality between the device and the Smart Home Controller. Possible values are `BAD`, `MEDIUM`, `NORMAL`, `GOOD` and `UNKNOWN`. | + ### Motion Detector Detects every movement through an intelligent combination of passive infra-red technology and an additional temperature sensor. 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 b87a217a301e0..7acb0c383f86a 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 @@ -36,6 +36,7 @@ public class BoschSHCBindingConstants { public static final ThingTypeUID THING_TYPE_INWALL_SWITCH = new ThingTypeUID(BINDING_ID, "in-wall-switch"); public static final ThingTypeUID THING_TYPE_TWINGUARD = new ThingTypeUID(BINDING_ID, "twinguard"); public static final ThingTypeUID THING_TYPE_WINDOW_CONTACT = new ThingTypeUID(BINDING_ID, "window-contact"); + public static final ThingTypeUID THING_TYPE_WINDOW_CONTACT_2 = new ThingTypeUID(BINDING_ID, "window-contact-2"); public static final ThingTypeUID THING_TYPE_MOTION_DETECTOR = new ThingTypeUID(BINDING_ID, "motion-detector"); public static final ThingTypeUID THING_TYPE_SHUTTER_CONTROL = new ThingTypeUID(BINDING_ID, "shutter-control"); public static final ThingTypeUID THING_TYPE_THERMOSTAT = new ThingTypeUID(BINDING_ID, "thermostat"); @@ -88,6 +89,8 @@ public class BoschSHCBindingConstants { public static final String CHANNEL_SMOKE_CHECK = "smoke-check"; public static final String CHANNEL_SILENT_MODE = "silent-mode"; public static final String CHANNEL_ILLUMINANCE = "illuminance"; + public static final String CHANNEL_BYPASS_STATE = "bypass-state"; + public static final String CHANNEL_COMMUNICATION_QUALITY = "communication-quality"; public static final String CHANNEL_USER_DEFINED_STATE = "user-state"; 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 010a46fc1e259..9ad6154450905 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 @@ -34,6 +34,7 @@ import org.openhab.binding.boschshc.internal.devices.twinguard.TwinguardHandler; import org.openhab.binding.boschshc.internal.devices.userdefinedstate.UserStateHandler; import org.openhab.binding.boschshc.internal.devices.wallthermostat.WallThermostatHandler; +import org.openhab.binding.boschshc.internal.devices.windowcontact.WindowContact2Handler; import org.openhab.binding.boschshc.internal.devices.windowcontact.WindowContactHandler; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Thing; @@ -73,6 +74,7 @@ public ThingTypeHandlerMapping(ThingTypeUID thingTypeUID, Function SUPPORTED_THING_TYPES = Set.of( BoschSHCBindingConstants.THING_TYPE_INWALL_SWITCH, BoschSHCBindingConstants.THING_TYPE_TWINGUARD, - BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT, BoschSHCBindingConstants.THING_TYPE_MOTION_DETECTOR, - BoschSHCBindingConstants.THING_TYPE_SHUTTER_CONTROL, BoschSHCBindingConstants.THING_TYPE_THERMOSTAT, - BoschSHCBindingConstants.THING_TYPE_CLIMATE_CONTROL, BoschSHCBindingConstants.THING_TYPE_WALL_THERMOSTAT, - BoschSHCBindingConstants.THING_TYPE_CAMERA_360, BoschSHCBindingConstants.THING_TYPE_CAMERA_EYES, + BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT, BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT_2, + BoschSHCBindingConstants.THING_TYPE_MOTION_DETECTOR, BoschSHCBindingConstants.THING_TYPE_SHUTTER_CONTROL, + BoschSHCBindingConstants.THING_TYPE_THERMOSTAT, BoschSHCBindingConstants.THING_TYPE_CLIMATE_CONTROL, + BoschSHCBindingConstants.THING_TYPE_WALL_THERMOSTAT, BoschSHCBindingConstants.THING_TYPE_CAMERA_360, + BoschSHCBindingConstants.THING_TYPE_CAMERA_EYES, BoschSHCBindingConstants.THING_TYPE_INTRUSION_DETECTION_SYSTEM, BoschSHCBindingConstants.THING_TYPE_SMART_PLUG_COMPACT, BoschSHCBindingConstants.THING_TYPE_SMART_BULB, BoschSHCBindingConstants.THING_TYPE_SMOKE_DETECTOR); @@ -83,6 +84,7 @@ public class ThingDiscoveryService extends AbstractDiscoveryService implements T new AbstractMap.SimpleEntry<>("HUE_LIGHT", BoschSHCBindingConstants.THING_TYPE_SMART_BULB), new AbstractMap.SimpleEntry<>("LEDVANCE_LIGHT", BoschSHCBindingConstants.THING_TYPE_SMART_BULB), new AbstractMap.SimpleEntry<>("SWD", BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT), + new AbstractMap.SimpleEntry<>("SWD2", BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT_2), new AbstractMap.SimpleEntry<>("TRV", BoschSHCBindingConstants.THING_TYPE_THERMOSTAT) // Future Extension: map deviceModel names to BoschSHC Thing Types when they are supported // new AbstractMap.SimpleEntry<>("SMOKE_DETECTION_SYSTEM", BoschSHCBindingConstants.), diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/BypassService.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/BypassService.java new file mode 100644 index 0000000000000..0833589ced8e8 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/BypassService.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2010-2023 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.bypass; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.boschshc.internal.services.BoschSHCService; +import org.openhab.binding.boschshc.internal.services.bypass.dto.BypassServiceState; + +/** + * Service for the bypass state of devices such as the Door/Window Contact II + * + * @author David Pace - Initial contribution + * + */ +@NonNullByDefault +public class BypassService extends BoschSHCService { + + public BypassService() { + super("Bypass", BypassServiceState.class); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassConfiguration.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassConfiguration.java new file mode 100644 index 0000000000000..a02a9b9bce9b2 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassConfiguration.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2010-2023 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.bypass.dto; + +/** + * Configuration object of a bypass configuration. + *

+ * Example JSON: + * + *

+ * "configuration": {
+ *   "enabled": false,
+ *   "timeout": 5,
+ *   "infinite": false
+ * }
+ * 
+ * + * @author David Pace - Initial contribution + * + */ +public class BypassConfiguration { + + public boolean enabled; + + public int timeout; + + public boolean infinite; +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassServiceState.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassServiceState.java new file mode 100644 index 0000000000000..2c8b2bff839fd --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassServiceState.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2010-2023 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.bypass.dto; + +import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState; + +/** + * Bypass service state for Door/Window Contact II + *

+ * Example JSON: + * + *

+ * {
+ *   "@type": "bypassState",
+ *   "state": "BYPASS_INACTIVE",
+ *   "configuration": {
+ *     "enabled": false,
+ *     "timeout": 5,
+ *     "infinite": false
+ *   }
+ * }
+ * 
+ * + * @author David Pace - Initial contribution + * + */ +public class BypassServiceState extends BoschSHCServiceState { + + public BypassServiceState() { + super("bypassState"); + } + + public BypassState state; + + public BypassConfiguration configuration; +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassState.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassState.java new file mode 100644 index 0000000000000..ef034f1f455ad --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassState.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2010-2023 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.bypass.dto; + +/** + * Possible states of the bypass service. + * + * @author David Pace - Initial contribution + * + */ +public enum BypassState { + BYPASS_INACTIVE, + BYPASS_ACTIVE, + UNKNOWN +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/CommunicationQualityService.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/CommunicationQualityService.java new file mode 100644 index 0000000000000..ab1fcd004faf6 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/CommunicationQualityService.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2010-2023 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.communicationquality; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.boschshc.internal.services.BoschSHCService; +import org.openhab.binding.boschshc.internal.services.communicationquality.dto.CommunicationQualityServiceState; + +/** + * Service for querying the communication quality between a device and the Smart Home Controller. + * + * @author David Pace - Initial contribution + * + */ +@NonNullByDefault +public class CommunicationQualityService extends BoschSHCService { + + public CommunicationQualityService() { + super("CommunicationQuality", CommunicationQualityServiceState.class); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/dto/CommunicationQualityServiceState.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/dto/CommunicationQualityServiceState.java new file mode 100644 index 0000000000000..cd08ef5e4d60d --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/dto/CommunicationQualityServiceState.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2010-2023 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.communicationquality.dto; + +import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState; + +/** + * State of the communication quality service. + *

+ * Example JSON: + * + *

+ * {
+ *   "@type": "communicationQualityState",
+ *   "quality": "UNKNOWN"
+ * }
+ * 
+ * + * @author David Pace - Initial contribution + * + */ +public class CommunicationQualityServiceState extends BoschSHCServiceState { + + public CommunicationQualityServiceState() { + super("communicationQualityState"); + } + + public CommunicationQualityState quality; +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/dto/CommunicationQualityState.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/dto/CommunicationQualityState.java new file mode 100644 index 0000000000000..ca8c2b7444ea5 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/dto/CommunicationQualityState.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2010-2023 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.communicationquality.dto; + +/** + * Possible states for the communication quality between a device and the bridge. + * + * @author David Pace - Initial contribution + * + */ +public enum CommunicationQualityState { + BAD, + MEDIUM, + NORMAL, + GOOD, + UNKNOWN +} 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 12375ea375b08..64a20d9e46d63 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 @@ -35,6 +35,8 @@ thing-type.boschshc.user-defined-state.label = User-defined State thing-type.boschshc.user-defined-state.description = A User-defined state. 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. +thing-type.boschshc.window-contact-2.label = Door/Window Contact II +thing-type.boschshc.window-contact-2.description = Detects open windows and doors and features an additional button. thing-type.boschshc.window-contact.label = Door/Window Contact thing-type.boschshc.window-contact.description = Detects open windows and doors. @@ -69,6 +71,11 @@ channel-type.boschshc.arming-state.description = The arming state of the intrusi 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.bypass-state.label = Bypass State +channel-type.boschshc.bypass-state.description = Indicates whether the device is bypassed. +channel-type.boschshc.bypass-state.state.option.BYPASS_INACTIVE = Bypass is not active +channel-type.boschshc.bypass-state.state.option.BYPASS_ACTIVE = Bypass is active +channel-type.boschshc.bypass-state.state.option.UNKNOWN = Bypass state cannot be determined 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 @@ -80,6 +87,13 @@ channel-type.boschshc.combined-rating.description = Combined rating of the air q channel-type.boschshc.combined-rating.state.option.GOOD = Good Quality channel-type.boschshc.combined-rating.state.option.MEDIUM = Medium Quality channel-type.boschshc.combined-rating.state.option.BAD = Bad Quality +channel-type.boschshc.communication-quality.label = Communication Quality +channel-type.boschshc.communication-quality.description = The quality of communication between a device and the Bosch Smart Home Controller. +channel-type.boschshc.communication-quality.state.option.BAD = Bad +channel-type.boschshc.communication-quality.state.option.MEDIUM = Medium +channel-type.boschshc.communication-quality.state.option.NORMAL = Normal +channel-type.boschshc.communication-quality.state.option.GOOD = Good +channel-type.boschshc.communication-quality.state.option.UNKNOWN = Unknown 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 @@ -93,6 +107,8 @@ channel-type.boschshc.humidity-rating.state.option.MEDIUM = Medium Humidity channel-type.boschshc.humidity-rating.state.option.BAD = Bad Humidity channel-type.boschshc.humidity.label = Humidity channel-type.boschshc.humidity.description = Current measured humidity. +channel-type.boschshc.illuminance.label = Illuminance +channel-type.boschshc.illuminance.description = The illuminance level measured by the sensor (0 to 1000). 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 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 83e69c05e58df..c4d50f19de8aa 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 @@ -103,6 +103,26 @@ + + + + + + + Detects open windows and doors and features an additional button. + + + + + + + + + + + + + @@ -573,5 +593,33 @@ State of user-defined state + + + String + + Indicates whether the device is bypassed. + + + + + + + + + + + String + + The quality of communication between a device and the Bosch Smart Home Controller. + + + + + + + + + + diff --git a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/windowcontact/WindowContact2HandlerTest.java b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/windowcontact/WindowContact2HandlerTest.java new file mode 100644 index 0000000000000..ce1166f0cdee5 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/windowcontact/WindowContact2HandlerTest.java @@ -0,0 +1,113 @@ +/** + * Copyright (c) 2010-2023 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.windowcontact; + +import static org.mockito.Mockito.verify; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.junit.jupiter.api.Test; +import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants; +import org.openhab.core.library.types.StringType; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.ThingTypeUID; + +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; + +/** + * Unit tests for {@link WindowContact2Handler}. + * + * @author David Pace - Initial contribution + * + */ +@NonNullByDefault +class WindowContact2HandlerTest extends WindowContactHandlerTest { + + @Override + protected WindowContactHandler createFixture() { + return new WindowContact2Handler(getThing()); + } + + @Override + protected ThingTypeUID getThingTypeUID() { + return BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT_2; + } + + @Test + void testUpdateChannelsBypassService() { + String json = """ + { + "@type": "bypassState", + "state": "BYPASS_INACTIVE", + "configuration": { + "enabled": false, + "timeout": 5, + "infinite": false + } + } + """; + + JsonElement jsonObject = JsonParser.parseString(json); + getFixture().processUpdate("Bypass", jsonObject); + verify(getCallback()).stateUpdated( + new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_BYPASS_STATE), + new StringType("BYPASS_INACTIVE")); + + json = """ + { + "@type": "bypassState", + "state": "BYPASS_ACTIVE", + "configuration": { + "enabled": false, + "timeout": 5, + "infinite": false + } + } + """; + + jsonObject = JsonParser.parseString(json); + getFixture().processUpdate("Bypass", jsonObject); + verify(getCallback()).stateUpdated( + new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_BYPASS_STATE), + new StringType("BYPASS_ACTIVE")); + } + + @Test + void testUpdateChannelsCommunicationQualityService() { + String json = """ + { + "@type": "communicationQualityState", + "quality": "UNKNOWN" + } + """; + JsonElement jsonObject = JsonParser.parseString(json); + + getFixture().processUpdate("CommunicationQuality", jsonObject); + verify(getCallback()).stateUpdated( + new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_COMMUNICATION_QUALITY), + new StringType("UNKNOWN")); + + json = """ + { + "@type": "communicationQualityState", + "quality": "GOOD" + } + """; + jsonObject = JsonParser.parseString(json); + + getFixture().processUpdate("CommunicationQuality", jsonObject); + verify(getCallback()).stateUpdated( + new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_COMMUNICATION_QUALITY), + new StringType("GOOD")); + } +}