forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[boschshc] Support for Universal Switch I + II (openhab#16274)
* [boschshc] Support for Universal Switch I + II - 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 openhab#16244 Signed-off-by: David Pace <dev@davidpace.de>
- Loading branch information
1 parent
cb001f0
commit 12ef727
Showing
15 changed files
with
542 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...rg/openhab/binding/boschshc/internal/devices/universalswitch/UniversalSwitch2Handler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.devices.universalswitch; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.core.i18n.TimeZoneProvider; | ||
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, TimeZoneProvider timeZoneProvider) { | ||
super(thing, timeZoneProvider); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...org/openhab/binding/boschshc/internal/devices/universalswitch/UniversalSwitchHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* 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.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.i18n.TimeZoneProvider; | ||
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 { | ||
|
||
private TimeZoneProvider timeZoneProvider; | ||
|
||
public UniversalSwitchHandler(Thing thing, TimeZoneProvider timeZoneProvider) { | ||
super(thing); | ||
this.timeZoneProvider = timeZoneProvider; | ||
} | ||
|
||
@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)); | ||
} | ||
|
||
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, timeZoneProvider.getTimeZone()))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...hc/src/main/java/org/openhab/binding/boschshc/internal/services/keypad/KeypadService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...src/main/java/org/openhab/binding/boschshc/internal/services/keypad/dto/KeyEventType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
28 changes: 28 additions & 0 deletions
28
...hshc/src/main/java/org/openhab/binding/boschshc/internal/services/keypad/dto/KeyName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.