Skip to content

Commit

Permalink
[boschshc] Support for Door/Window Contact II (openhab#16093)
Browse files Browse the repository at this point in the history
* [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 openhab#15954

Signed-off-by: David Pace <dev@davidpace.de>
Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
  • Loading branch information
david-pace authored and austvik committed Mar 27, 2024
1 parent 740d280 commit 94e92ea
Show file tree
Hide file tree
Showing 17 changed files with 605 additions and 4 deletions.
15 changes: 15 additions & 0 deletions bundles/org.openhab.binding.boschshc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -96,6 +97,20 @@ Detects open windows and doors.
| battery-level | Number | &#9744; | 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 | &#9744; | 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 | &#9744; | Contact state of the device. |
| battery-level | Number | &#9744; | 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 | &#9744; | Indicates whether the battery is low (`ON`) or OK (`OFF`). |
| bypass | Switch | &#9744; | Indicates whether the device is currently bypassed. Possible values are `ON`,`OFF` and `UNDEF` if the bypass state cannot be determined. |
| signal-strength | Number | &#9744; | 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,6 +74,7 @@ public ThingTypeHandlerMapping(ThingTypeUID thingTypeUID, Function<Thing, BaseTh
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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ public class ThingDiscoveryService extends AbstractDiscoveryService implements T

protected static final Set<ThingTypeUID> 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);
Expand All @@ -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.),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<BypassServiceState> {

public BypassService() {
super("Bypass", BypassServiceState.class);
}
}
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* Example JSON:
*
* <pre>
* "configuration": {
* "enabled": false,
* "timeout": 5,
* "infinite": false
* }
* </pre>
*
* @author David Pace - Initial contribution
*
*/
public class BypassConfiguration {

public boolean enabled;

public int timeout;

public boolean infinite;
}
Original file line number Diff line number Diff line change
@@ -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
* <p>
* Example JSON:
*
* <pre>
* {
* "@type": "bypassState",
* "state": "BYPASS_INACTIVE",
* "configuration": {
* "enabled": false,
* "timeout": 5,
* "infinite": false
* }
* }
* </pre>
*
* @author David Pace - Initial contribution
*
*/
public class BypassServiceState extends BoschSHCServiceState {

public BypassServiceState() {
super("bypassState");
}

public BypassState state;

public BypassConfiguration configuration;
}
Original file line number Diff line number Diff line change
@@ -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 <code>ON</code>, <code>OFF</code> or <code>UNDEF</code>
*/
public State toOnOffTypeOrUndef() {
return switch (this) {
case BYPASS_ACTIVE -> OnOffType.ON;
case BYPASS_INACTIVE -> OnOffType.OFF;
default -> UnDefType.UNDEF;
};
}
}
Original file line number Diff line number Diff line change
@@ -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<CommunicationQualityServiceState> {

public CommunicationQualityService() {
super("CommunicationQuality", CommunicationQualityServiceState.class);
}
}
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* Example JSON:
*
* <pre>
* {
* "@type": "communicationQualityState",
* "quality": "UNKNOWN"
* }
* </pre>
*
* @author David Pace - Initial contribution
*
*/
public class CommunicationQualityServiceState extends BoschSHCServiceState {

public CommunicationQualityServiceState() {
super("communicationQualityState");
}

public CommunicationQualityState quality;
}

0 comments on commit 94e92ea

Please sign in to comment.