diff --git a/bundles/org.openhab.binding.boschshc/README.md b/bundles/org.openhab.binding.boschshc/README.md index 4b75bb23c22..7758c2d52ae 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 | Switch | ☐ | Indicates whether the device is currently bypassed. Possible values are `ON`,`OFF` and `UNDEF` if the bypass state cannot be determined. | +| signal-strength | Number | ☐ | Communication quality between the device and the Smart Home Controller. Possible values range between 0 (unknown) and 4 (best signal strength). | + ### 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 b87a217a301..957fa949023 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_SIGNAL_STRENGTH = "signal-strength"; 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 010a46fc1e2..9ad61544509 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.thermostat.ThermostatHandle 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 class BoschSHCHandlerFactory extends BaseThingHandlerFactory { new ThingTypeHandlerMapping(THING_TYPE_INWALL_SWITCH, LightControlHandler::new), new ThingTypeHandlerMapping(THING_TYPE_TWINGUARD, TwinguardHandler::new), new ThingTypeHandlerMapping(THING_TYPE_WINDOW_CONTACT, WindowContactHandler::new), + new ThingTypeHandlerMapping(THING_TYPE_WINDOW_CONTACT_2, WindowContact2Handler::new), new ThingTypeHandlerMapping(THING_TYPE_MOTION_DETECTOR, MotionDetectorHandler::new), new ThingTypeHandlerMapping(THING_TYPE_SHUTTER_CONTROL, ShutterControlHandler::new), new ThingTypeHandlerMapping(THING_TYPE_THERMOSTAT, ThermostatHandler::new), diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/windowcontact/WindowContact2Handler.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/windowcontact/WindowContact2Handler.java new file mode 100644 index 00000000000..656104a1eb8 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/windowcontact/WindowContact2Handler.java @@ -0,0 +1,57 @@ +/** + * 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.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_BYPASS_STATE; +import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH; + +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException; +import org.openhab.binding.boschshc.internal.services.bypass.BypassService; +import org.openhab.binding.boschshc.internal.services.bypass.dto.BypassServiceState; +import org.openhab.binding.boschshc.internal.services.communicationquality.CommunicationQualityService; +import org.openhab.binding.boschshc.internal.services.communicationquality.dto.CommunicationQualityServiceState; +import org.openhab.core.thing.Thing; + +/** + * Handler for Door/Window Contact II + * + * @author David Pace - Initial contribution + * + */ +@NonNullByDefault +public class WindowContact2Handler extends WindowContactHandler { + + public WindowContact2Handler(Thing thing) { + super(thing); + } + + @Override + protected void initializeServices() throws BoschSHCException { + super.initializeServices(); + + this.createService(BypassService::new, this::updateChannels, List.of(CHANNEL_BYPASS_STATE), true); + this.createService(CommunicationQualityService::new, this::updateChannels, List.of(CHANNEL_SIGNAL_STRENGTH), + true); + } + + private void updateChannels(BypassServiceState bypassServiceState) { + updateState(CHANNEL_BYPASS_STATE, bypassServiceState.state.toOnOffTypeOrUndef()); + } + + private void updateChannels(CommunicationQualityServiceState communicationQualityServiceState) { + updateState(CHANNEL_SIGNAL_STRENGTH, communicationQualityServiceState.quality.toSystemSignalStrength()); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/discovery/ThingDiscoveryService.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/discovery/ThingDiscoveryService.java index e2e005e756a..6a8918593d5 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/discovery/ThingDiscoveryService.java +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/discovery/ThingDiscoveryService.java @@ -57,10 +57,11 @@ public class ThingDiscoveryService extends AbstractDiscoveryService implements T protected static final Set 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 00000000000..0833589ced8 --- /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 00000000000..a02a9b9bce9 --- /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 00000000000..2c8b2bff839 --- /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 00000000000..ea84939e3e4 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassState.java @@ -0,0 +1,42 @@ +/** + * 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.core.library.types.OnOffType; +import org.openhab.core.types.State; +import org.openhab.core.types.UnDefType; + +/** + * State indicating whether a device is currently bypassed. + * + * @author David Pace - Initial contribution + * + */ +public enum BypassState { + BYPASS_INACTIVE, + BYPASS_ACTIVE, + UNKNOWN; + + /** + * Converts this Bosch-specific bypass state to an openHAB-compliant state for a switch. + * + * @return ON, OFF or UNDEF + */ + public State toOnOffTypeOrUndef() { + return switch (this) { + case BYPASS_ACTIVE -> OnOffType.ON; + case BYPASS_INACTIVE -> OnOffType.OFF; + default -> UnDefType.UNDEF; + }; + } +} 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 00000000000..ab1fcd004fa --- /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 00000000000..cd08ef5e4d6 --- /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 00000000000..f0fba0e4a1e --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/communicationquality/dto/CommunicationQualityState.java @@ -0,0 +1,53 @@ +/** + * 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.core.library.types.DecimalType; + +/** + * 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, + FETCHING; + + /** + * Converts this Bosch-specific communication quality state into a numeric state + * for the system channel of type signal-strength. + * + * @return + */ + public DecimalType toSystemSignalStrength() { + switch (this) { + case BAD: + return new DecimalType(1); + case MEDIUM: + return new DecimalType(2); + case NORMAL: + return new DecimalType(3); + case GOOD: + return new DecimalType(4); + default: + // includes UNKNOWN and FETCHING + return new DecimalType(0); + } + } +} 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 12375ea375b..e4f04b265aa 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,10 @@ 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 currently bypassed. +channel-type.boschshc.bypass-state.state.option.OFF = Device is currently not bypassed +channel-type.boschshc.bypass-state.state.option.ON = Device is currently bypassed 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 @@ -93,6 +99,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 83e69c05e58..93b2b3fe39d 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. + + + + + + + + + + + + + @@ -574,4 +594,16 @@ State of user-defined state + + Switch + + Indicates whether the device is currently bypassed. + + + + + + + + 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 00000000000..835f2091b6a --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/windowcontact/WindowContact2HandlerTest.java @@ -0,0 +1,130 @@ +/** + * 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.DecimalType; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.ThingTypeUID; +import org.openhab.core.types.UnDefType; + +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), OnOffType.OFF); + + 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), OnOffType.ON); + + json = """ + { + "@type": "bypassState", + "state": "UNKNOWN", + "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), UnDefType.UNDEF); + } + + @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_SIGNAL_STRENGTH), + new DecimalType(0)); + + json = """ + { + "@type": "communicationQualityState", + "quality": "GOOD" + } + """; + jsonObject = JsonParser.parseString(json); + + getFixture().processUpdate("CommunicationQuality", jsonObject); + verify(getCallback()).stateUpdated( + new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH), + new DecimalType(4)); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassStateTest.java b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassStateTest.java new file mode 100644 index 00000000000..74e450bb8ce --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/bypass/dto/BypassStateTest.java @@ -0,0 +1,35 @@ +/** + * 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 static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.types.UnDefType; + +/** + * Unit tests for {@link BypassState}. + * + * @author David Pace - Initial contribution + * + */ +class BypassStateTest { + + @Test + void testToOnOffTypeOrUndef() { + assertEquals(OnOffType.ON, BypassState.BYPASS_ACTIVE.toOnOffTypeOrUndef()); + assertEquals(OnOffType.OFF, BypassState.BYPASS_INACTIVE.toOnOffTypeOrUndef()); + assertEquals(UnDefType.UNDEF, BypassState.UNKNOWN.toOnOffTypeOrUndef()); + } +} diff --git a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/communicationquality/dto/CommunicationQualityStateTest.java b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/communicationquality/dto/CommunicationQualityStateTest.java new file mode 100644 index 00000000000..053336da709 --- /dev/null +++ b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/services/communicationquality/dto/CommunicationQualityStateTest.java @@ -0,0 +1,37 @@ +/** + * 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 static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.openhab.core.library.types.DecimalType; + +/** + * Unit tests for {@link CommunicationQualityState}. + * + * @author David Pace - Initial contribution + * + */ +class CommunicationQualityStateTest { + + @Test + void testToSystemSignalStrength() { + assertEquals(new DecimalType(0), CommunicationQualityState.UNKNOWN.toSystemSignalStrength()); + assertEquals(new DecimalType(0), CommunicationQualityState.FETCHING.toSystemSignalStrength()); + assertEquals(new DecimalType(1), CommunicationQualityState.BAD.toSystemSignalStrength()); + assertEquals(new DecimalType(2), CommunicationQualityState.MEDIUM.toSystemSignalStrength()); + assertEquals(new DecimalType(3), CommunicationQualityState.NORMAL.toSystemSignalStrength()); + assertEquals(new DecimalType(4), CommunicationQualityState.GOOD.toSystemSignalStrength()); + } +}