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] Add support for Light/Shutter Control II (openhab#16400)
* [boschshc] Add support for Shutter Control II (openhab#14562) * add new channel type for child protection Signed-off-by: David Pace <dev@davidpace.de>
- Loading branch information
1 parent
afc6d94
commit b77172c
Showing
36 changed files
with
1,670 additions
and
154 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
61 changes: 61 additions & 0 deletions
61
...g/openhab/binding/boschshc/internal/devices/AbstractPowerSwitchHandlerWithPowerMeter.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,61 @@ | ||
/** | ||
* 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; | ||
|
||
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_ENERGY_CONSUMPTION; | ||
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_POWER_CONSUMPTION; | ||
|
||
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.powermeter.PowerMeterService; | ||
import org.openhab.binding.boschshc.internal.services.powermeter.dto.PowerMeterServiceState; | ||
import org.openhab.binding.boschshc.internal.services.powerswitch.PowerSwitchService; | ||
import org.openhab.core.library.types.QuantityType; | ||
import org.openhab.core.library.unit.Units; | ||
import org.openhab.core.thing.Thing; | ||
|
||
/** | ||
* Abstract handler implementation for devices providing a {@link PowerSwitchService} and a {@link PowerMeterService}. | ||
* <p> | ||
* Examples for such devices are smart plugs and in-wall switches. | ||
* | ||
* @author David Pace - Initial contribution | ||
* | ||
*/ | ||
@NonNullByDefault | ||
public abstract class AbstractPowerSwitchHandlerWithPowerMeter extends AbstractPowerSwitchHandler { | ||
|
||
protected AbstractPowerSwitchHandlerWithPowerMeter(Thing thing) { | ||
super(thing); | ||
} | ||
|
||
@Override | ||
protected void initializeServices() throws BoschSHCException { | ||
super.initializeServices(); | ||
|
||
this.createService(PowerMeterService::new, this::updateChannels, | ||
List.of(CHANNEL_POWER_CONSUMPTION, CHANNEL_ENERGY_CONSUMPTION), true); | ||
} | ||
|
||
/** | ||
* Updates the channels which are linked to the {@link PowerMeterService} of the device. | ||
* | ||
* @param state Current state of {@link PowerMeterService}. | ||
*/ | ||
private void updateChannels(PowerMeterServiceState state) { | ||
super.updateState(CHANNEL_POWER_CONSUMPTION, new QuantityType<>(state.powerConsumption, Units.WATT)); | ||
super.updateState(CHANNEL_ENERGY_CONSUMPTION, new QuantityType<>(state.energyConsumption, Units.WATT_HOUR)); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...chshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschDeviceIdUtils.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,69 @@ | ||
/** | ||
* 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; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* Utilities for handling parent/child relations in Bosch device IDs. | ||
* | ||
* @author David Pace - Initial contribution | ||
* | ||
*/ | ||
@NonNullByDefault | ||
public final class BoschDeviceIdUtils { | ||
|
||
private static final String CHILD_ID_SEPARATOR = "#"; | ||
|
||
private BoschDeviceIdUtils() { | ||
// Utility Class | ||
} | ||
|
||
/** | ||
* Returns whether the given device ID is a child device ID. | ||
* <p> | ||
* Example for a parent device ID: | ||
* | ||
* <pre> | ||
* hdm:ZigBee:70ac08fffefead2d | ||
* </pre> | ||
* | ||
* Example for a child device ID: | ||
* | ||
* <pre> | ||
* hdm:ZigBee:70ac08fffefead2d#2 | ||
* </pre> | ||
* | ||
* @param deviceId the Bosch device ID to check | ||
* @return <code>true</code> if the device ID contains a hash character, <code>false</code> otherwise | ||
*/ | ||
public static boolean isChildDeviceId(String deviceId) { | ||
return deviceId.contains(CHILD_ID_SEPARATOR); | ||
} | ||
|
||
/** | ||
* If the given device ID is a child device ID, the parent device ID is derived by cutting off the part starting | ||
* from the hash character. | ||
* | ||
* @param deviceId a device ID | ||
* @return the parent device ID, if derivable. Otherwise the given ID is returned. | ||
*/ | ||
public static String getParentDeviceId(String deviceId) { | ||
int hashIndex = deviceId.indexOf(CHILD_ID_SEPARATOR); | ||
if (hashIndex < 0) { | ||
return deviceId; | ||
} | ||
|
||
return deviceId.substring(0, hashIndex); | ||
} | ||
} |
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
Oops, something went wrong.