Skip to content

Commit

Permalink
[boschshc] Support for Universal Switch I + II
Browse files Browse the repository at this point in the history
- add thing type and channel type definitions
- re-generate i18n file
- add constants
- add model classes and enums
- implement service and handlers
- register handlers in factory
- register devices in discovery

closes #16244

Signed-off-by: David Pace <dev@davidpace.de>
  • Loading branch information
david-pace committed Jan 13, 2024
1 parent d5bbda6 commit eb4d9bd
Show file tree
Hide file tree
Showing 14 changed files with 459 additions and 2 deletions.
25 changes: 25 additions & 0 deletions bundles/org.openhab.binding.boschshc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,31 @@ Individual states can be activated/deactivated and can be used as triggers, cond
|-----------------|-----------| :------: |--------------------------------------------|
| user-state | Switch | &#9745; | Switches the User-defined state on or off. |

### Universal Switch

A universally configurable switch with two buttons.

**Thing Type ID**: `universal-switch`

| Channel Type ID | Item Type | Writable | Description |
| ------------------- | -------------------- | :------: | ----------------------------------------- |
| key-code | Number:Dimensionless | &#9744; | Integer code of the key that was pressed. |
| key-name | String | &#9744; | Name of a key pressed on a device. Possible values on Universal Switch: `LOWER_BUTTON`, `UPPER_BUTTON`. |
| key-event-type | String | &#9744; | Indicates how the key was pressed. Possible values are `PRESS_SHORT`, `PRESS_LONG` and `PRESS_LONG_RELEASED`. |
| key-event-timestamp | DateTime | &#9744; | Timestamp indicating when the key was pressed. |

### Universal Switch II

A universally configurable switch with four buttons.

**Thing Type ID**: `universal-switch-2`

| Channel Type ID | Item Type | Writable | Description |
| ------------------- | -------------------- | :------: | ----------------------------------------- |
| key-code | Number:Dimensionless | &#9744; | Integer code of the key that was pressed. |
| key-name | String | &#9744; | Name of the key that was pressed. Possible values on Universal Switch II: `LOWER_LEFT_BUTTON`, `LOWER_RIGHT_BUTTON`, `UPPER_LEFT_BUTTON`, `UPPER_RIGHT_BUTTON`. |
| key-event-type | String | &#9744; | Indicates how the key was pressed. Possible values are `PRESS_SHORT`, `PRESS_LONG` and `PRESS_LONG_RELEASED`. |
| key-event-timestamp | DateTime | &#9744; | Timestamp indicating when the key was pressed. |

## Limitations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class BoschSHCBindingConstants {
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");
public static final ThingTypeUID THING_TYPE_SMOKE_DETECTOR = new ThingTypeUID(BINDING_ID, "smoke-detector");
public static final ThingTypeUID THING_TYPE_UNIVERSAL_SWITCH = new ThingTypeUID(BINDING_ID, "universal-switch");
public static final ThingTypeUID THING_TYPE_UNIVERSAL_SWITCH_2 = new ThingTypeUID(BINDING_ID, "universal-switch-2");

public static final ThingTypeUID THING_TYPE_USER_DEFINED_STATE = new ThingTypeUID(BINDING_ID, "user-defined-state");

Expand Down Expand Up @@ -91,6 +93,10 @@ public class BoschSHCBindingConstants {
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_KEY_CODE = "key-code";
public static final String CHANNEL_KEY_NAME = "key-name";
public static final String CHANNEL_KEY_EVENT_TYPE = "key-event-type";
public static final String CHANNEL_KEY_EVENT_TIMESTAMP = "key-event-timestamp";

public static final String CHANNEL_USER_DEFINED_STATE = "user-state";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.openhab.binding.boschshc.internal.devices.smokedetector.SmokeDetectorHandler;
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.universalswitch.UniversalSwitch2Handler;
import org.openhab.binding.boschshc.internal.devices.universalswitch.UniversalSwitchHandler;
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;
Expand Down Expand Up @@ -86,7 +88,9 @@ public ThingTypeHandlerMapping(ThingTypeUID thingTypeUID, Function<Thing, BaseTh
new ThingTypeHandlerMapping(THING_TYPE_SMART_PLUG_COMPACT, PlugHandler::new),
new ThingTypeHandlerMapping(THING_TYPE_SMART_BULB, SmartBulbHandler::new),
new ThingTypeHandlerMapping(THING_TYPE_SMOKE_DETECTOR, SmokeDetectorHandler::new),
new ThingTypeHandlerMapping(THING_TYPE_USER_DEFINED_STATE, UserStateHandler::new));
new ThingTypeHandlerMapping(THING_TYPE_USER_DEFINED_STATE, UserStateHandler::new),
new ThingTypeHandlerMapping(THING_TYPE_UNIVERSAL_SWITCH, UniversalSwitchHandler::new),
new ThingTypeHandlerMapping(THING_TYPE_UNIVERSAL_SWITCH_2, UniversalSwitch2Handler::new));

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2010-2024 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.universalswitch;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.Thing;

/**
* Handler for a universally configurable switch with four buttons.
*
* @author David Pace - Initial contribution
*
*/
@NonNullByDefault
public class UniversalSwitch2Handler extends UniversalSwitchHandler {

public UniversalSwitch2Handler(Thing thing) {
super(thing);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright (c) 2010-2024 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.universalswitch;

import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_KEY_CODE;
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_KEY_EVENT_TIMESTAMP;
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_KEY_EVENT_TYPE;
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_KEY_NAME;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.boschshc.internal.devices.AbstractBatteryPoweredDeviceHandler;
import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
import org.openhab.binding.boschshc.internal.services.keypad.KeypadService;
import org.openhab.binding.boschshc.internal.services.keypad.dto.KeypadServiceState;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.thing.Thing;

/**
* Handler for a universally configurable switch with two buttons.
*
* @author David Pace - Initial contribution
*
*/
@NonNullByDefault
public class UniversalSwitchHandler extends AbstractBatteryPoweredDeviceHandler {

public UniversalSwitchHandler(Thing thing) {
super(thing);
}

@Override
protected void initializeServices() throws BoschSHCException {
super.initializeServices();

createService(KeypadService::new, this::updateChannels,
List.of(CHANNEL_KEY_CODE, CHANNEL_KEY_NAME, CHANNEL_KEY_EVENT_TYPE, CHANNEL_KEY_EVENT_TIMESTAMP), true);
}

private void updateChannels(KeypadServiceState keypadServiceState) {
updateState(CHANNEL_KEY_CODE, new DecimalType(keypadServiceState.keyCode));
updateState(CHANNEL_KEY_NAME, new StringType(keypadServiceState.keyName.toString()));
updateState(CHANNEL_KEY_EVENT_TYPE, new StringType(keypadServiceState.eventType.toString()));

Instant instant = Instant.ofEpochMilli(keypadServiceState.eventTimestamp);
updateState(CHANNEL_KEY_EVENT_TIMESTAMP,
new DateTimeType(ZonedDateTime.ofInstant(instant, ZoneId.systemDefault())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ public class ThingDiscoveryService extends AbstractThingHandlerDiscoveryService<
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)
new AbstractMap.SimpleEntry<>("TRV", BoschSHCBindingConstants.THING_TYPE_THERMOSTAT),
new AbstractMap.SimpleEntry<>("WRC2", BoschSHCBindingConstants.THING_TYPE_UNIVERSAL_SWITCH),
new AbstractMap.SimpleEntry<>("SWITCH2", BoschSHCBindingConstants.THING_TYPE_UNIVERSAL_SWITCH_2)
// Future Extension: map deviceModel names to BoschSHC Thing Types when they are supported
// new AbstractMap.SimpleEntry<>("SMOKE_DETECTION_SYSTEM", BoschSHCBindingConstants.),
// new AbstractMap.SimpleEntry<>("PRESENCE_SIMULATION_SERVICE", BoschSHCBindingConstants.),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2010-2024 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.keypad;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.boschshc.internal.services.BoschSHCService;
import org.openhab.binding.boschshc.internal.services.keypad.dto.KeypadServiceState;

/**
* Service for the keypads for Universal Switches.
*
* @author David Pace - Initial contribution
*
*/
@NonNullByDefault
public class KeypadService extends BoschSHCService<KeypadServiceState> {

public KeypadService() {
super("Keypad", KeypadServiceState.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2010-2024 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.keypad.dto;

/**
* Event types of keys/buttons pressed on Universal Switches.
*
* @author David Pace - Initial contribution
*
*/
public enum KeyEventType {
PRESS_SHORT,
PRESS_LONG,
PRESS_LONG_RELEASED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2010-2024 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.keypad.dto;

/**
* Key names of keys/buttons pressed on Universal Switches.
*
* @author David Pace - Initial contribution
*
*/
public enum KeyName {
LOWER_BUTTON,
UPPER_BUTTON,
LOWER_LEFT_BUTTON,
LOWER_RIGHT_BUTTON,
UPPER_LEFT_BUTTON,
UPPER_RIGHT_BUTTON
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2010-2024 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.keypad.dto;

import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState;
import org.openhab.binding.boschshc.internal.services.keypad.KeypadService;

/**
* State object of the {@link KeypadService}.
* <p>
* Example JSON:
*
* <pre>
* {
* "@type":"keypadState",
* "keyCode":1,
* "keyName":"UPPER_LEFT_BUTTON",
* "eventType":"PRESS_SHORT",
* "eventTimestamp":1705130891435
* }
* </pre>
*
* @author David Pace - Initial contribution
*
*/
public class KeypadServiceState extends BoschSHCServiceState {

public KeypadServiceState() {
super("keypadState");
}

public int keyCode;

public KeyName keyName;

public KeyEventType eventType;

public long eventTimestamp;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ thing-type.boschshc.thermostat.label = Thermostat
thing-type.boschshc.thermostat.description = Radiator thermostat
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.universal-switch-2.label = Universal Switch II
thing-type.boschshc.universal-switch-2.description = Universally configurable switch with four buttons.
thing-type.boschshc.universal-switch.label = Universal Switch
thing-type.boschshc.universal-switch.description = Universally configurable switch with two buttons.
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
Expand Down Expand Up @@ -101,6 +105,14 @@ 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.key-code.label = Key Code
channel-type.boschshc.key-code.description = Integer code of the key that was pressed.
channel-type.boschshc.key-event-timestamp.label = Key Event Timestamp
channel-type.boschshc.key-event-timestamp.description = Timestamp indicating when the key was pressed.
channel-type.boschshc.key-event-type.label = Key Event Type
channel-type.boschshc.key-event-type.description = Indicates how the key was pressed. Possible values are PRESS_SHORT, PRESS_LONG and PRESS_LONG_RELEASED.
channel-type.boschshc.key-name.label = Key Name
channel-type.boschshc.key-name.description = Name of the key that was pressed.
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
Expand Down

0 comments on commit eb4d9bd

Please sign in to comment.