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 smart light bulbs (openhab#13725)
* [boschshc] Support smart light bulbs (openhab#13707) * add thing type definition for smart bulbs using system channels * add constants for thing type and channels * implement and register handler * implement binary switch service (to switch on/off) * implement multi-level switch service (allows to get/set brightness from 0-100%) * implement service to get and set colors * add unit tests for handler and state classes - update documentation Signed-off-by: David Pace <dev@davidpace.de> Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
- Loading branch information
1 parent
5108e26
commit e846de7
Showing
17 changed files
with
689 additions
and
3 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
117 changes: 117 additions & 0 deletions
117
...c/main/java/org/openhab/binding/boschshc/internal/devices/smartbulb/SmartBulbHandler.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,117 @@ | ||
/** | ||
* Copyright (c) 2010-2022 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.smartbulb; | ||
|
||
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.*; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.boschshc.internal.devices.BoschSHCDeviceHandler; | ||
import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException; | ||
import org.openhab.binding.boschshc.internal.services.binaryswitch.BinarySwitchService; | ||
import org.openhab.binding.boschshc.internal.services.binaryswitch.dto.BinarySwitchServiceState; | ||
import org.openhab.binding.boschshc.internal.services.hsbcoloractuator.HSBColorActuatorService; | ||
import org.openhab.binding.boschshc.internal.services.hsbcoloractuator.dto.HSBColorActuatorServiceState; | ||
import org.openhab.binding.boschshc.internal.services.multilevelswitch.MultiLevelSwitchService; | ||
import org.openhab.binding.boschshc.internal.services.multilevelswitch.dto.MultiLevelSwitchServiceState; | ||
import org.openhab.core.library.types.HSBType; | ||
import org.openhab.core.library.types.OnOffType; | ||
import org.openhab.core.library.types.PercentType; | ||
import org.openhab.core.thing.ChannelUID; | ||
import org.openhab.core.thing.Thing; | ||
import org.openhab.core.types.Command; | ||
|
||
/** | ||
* Handler for smart light bulbs connected via Zigbee, e.g. Ledvance Smart+ bulbs | ||
* | ||
* @author David Pace - Initial contribution | ||
* | ||
*/ | ||
@NonNullByDefault | ||
public class SmartBulbHandler extends BoschSHCDeviceHandler { | ||
|
||
private BinarySwitchService binarySwitchService; | ||
private HSBColorActuatorService hsbColorActuatorService; | ||
private MultiLevelSwitchService multiLevelSwitchService; | ||
|
||
public SmartBulbHandler(Thing thing) { | ||
super(thing); | ||
|
||
this.binarySwitchService = new BinarySwitchService(); | ||
this.multiLevelSwitchService = new MultiLevelSwitchService(); | ||
this.hsbColorActuatorService = new HSBColorActuatorService(); | ||
} | ||
|
||
@Override | ||
protected void initializeServices() throws BoschSHCException { | ||
super.initializeServices(); | ||
|
||
this.registerService(binarySwitchService, this::updateChannels, List.of(CHANNEL_POWER_SWITCH), true); | ||
this.registerService(multiLevelSwitchService, this::updateChannels, List.of(CHANNEL_BRIGHTNESS), true); | ||
this.registerService(hsbColorActuatorService, this::updateChannels, List.of(CHANNEL_COLOR), true); | ||
} | ||
|
||
@Override | ||
public void handleCommand(ChannelUID channelUID, Command command) { | ||
super.handleCommand(channelUID, command); | ||
|
||
switch (channelUID.getId()) { | ||
case CHANNEL_POWER_SWITCH: | ||
if (command instanceof OnOffType) { | ||
updateBinarySwitchState((OnOffType) command); | ||
} | ||
break; | ||
case CHANNEL_BRIGHTNESS: | ||
if (command instanceof PercentType) { | ||
updateMultiLevelSwitchState((PercentType) command); | ||
} | ||
break; | ||
case CHANNEL_COLOR: | ||
if (command instanceof HSBType) { | ||
updateColorState((HSBType) command); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
private void updateBinarySwitchState(OnOffType command) { | ||
BinarySwitchServiceState serviceState = new BinarySwitchServiceState(); | ||
serviceState.on = command == OnOffType.ON; | ||
this.updateServiceState(binarySwitchService, serviceState); | ||
} | ||
|
||
private void updateMultiLevelSwitchState(PercentType command) { | ||
MultiLevelSwitchServiceState serviceState = new MultiLevelSwitchServiceState(); | ||
serviceState.level = command.intValue(); | ||
this.updateServiceState(multiLevelSwitchService, serviceState); | ||
} | ||
|
||
private void updateColorState(HSBType command) { | ||
HSBColorActuatorServiceState serviceState = new HSBColorActuatorServiceState(); | ||
serviceState.rgb = command.getRGB(); | ||
this.updateServiceState(hsbColorActuatorService, serviceState); | ||
} | ||
|
||
private void updateChannels(BinarySwitchServiceState serviceState) { | ||
super.updateState(CHANNEL_POWER_SWITCH, serviceState.toOnOffType()); | ||
} | ||
|
||
private void updateChannels(MultiLevelSwitchServiceState serviceState) { | ||
super.updateState(CHANNEL_BRIGHTNESS, serviceState.toPercentType()); | ||
} | ||
|
||
private void updateChannels(HSBColorActuatorServiceState serviceState) { | ||
super.updateState(CHANNEL_COLOR, serviceState.toHSBType()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...java/org/openhab/binding/boschshc/internal/services/binaryswitch/BinarySwitchService.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-2022 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.binaryswitch; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.boschshc.internal.services.BoschSHCService; | ||
import org.openhab.binding.boschshc.internal.services.binaryswitch.dto.BinarySwitchServiceState; | ||
|
||
/** | ||
* Service for devices and services that can be turned on and off. | ||
* | ||
* @author David Pace - Initial contribution | ||
* | ||
*/ | ||
@NonNullByDefault | ||
public class BinarySwitchService extends BoschSHCService<BinarySwitchServiceState> { | ||
|
||
public BinarySwitchService() { | ||
super("BinarySwitch", BinarySwitchServiceState.class); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...openhab/binding/boschshc/internal/services/binaryswitch/dto/BinarySwitchServiceState.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,36 @@ | ||
/** | ||
* Copyright (c) 2010-2022 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.binaryswitch.dto; | ||
|
||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState; | ||
import org.openhab.core.library.types.OnOffType; | ||
|
||
/** | ||
* State for devices and services that can be turned on and off. | ||
* | ||
* @author David Pace - Initial contribution | ||
* | ||
*/ | ||
public class BinarySwitchServiceState extends BoschSHCServiceState { | ||
|
||
public BinarySwitchServiceState() { | ||
super("binarySwitchState"); | ||
} | ||
|
||
public boolean on; | ||
|
||
public @NonNull OnOffType toOnOffType() { | ||
return OnOffType.from(on); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../openhab/binding/boschshc/internal/services/hsbcoloractuator/HSBColorActuatorService.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-2022 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.hsbcoloractuator; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.boschshc.internal.services.BoschSHCService; | ||
import org.openhab.binding.boschshc.internal.services.hsbcoloractuator.dto.HSBColorActuatorServiceState; | ||
|
||
/** | ||
* Service for devices that can emit colored light. | ||
* | ||
* @author David Pace - Initial contribution | ||
* | ||
*/ | ||
@NonNullByDefault | ||
public class HSBColorActuatorService extends BoschSHCService<HSBColorActuatorServiceState> { | ||
|
||
public HSBColorActuatorService() { | ||
super("HSBColorActuator", HSBColorActuatorServiceState.class); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...penhab/binding/boschshc/internal/services/hsbcoloractuator/dto/ColorTemperatureRange.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,24 @@ | ||
/** | ||
* Copyright (c) 2010-2022 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.hsbcoloractuator.dto; | ||
|
||
/** | ||
* State representing the color temperature range of light bulbs. | ||
* | ||
* @author David Pace - Initial contribution | ||
* | ||
*/ | ||
public class ColorTemperatureRange { | ||
public int minCt; | ||
public int maxCt; | ||
} |
51 changes: 51 additions & 0 deletions
51
...binding/boschshc/internal/services/hsbcoloractuator/dto/HSBColorActuatorServiceState.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,51 @@ | ||
/** | ||
* Copyright (c) 2010-2022 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.hsbcoloractuator.dto; | ||
|
||
import java.awt.Color; | ||
|
||
import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState; | ||
import org.openhab.core.library.types.HSBType; | ||
|
||
/** | ||
* State representing colors of light bulbs. | ||
* | ||
* @author David Pace - Initial contribution | ||
* | ||
*/ | ||
public class HSBColorActuatorServiceState extends BoschSHCServiceState { | ||
|
||
public HSBColorActuatorServiceState() { | ||
super("colorState"); | ||
} | ||
|
||
/** | ||
* RGB value modeled as an sRGB integer value (bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue). | ||
* Alpha is set to the fixed value <code>255</code>. | ||
*/ | ||
public int rgb; | ||
|
||
public String gamut; | ||
|
||
public ColorTemperatureRange colorTemperatureRange; | ||
|
||
/** | ||
* Converts the combined {@link #rgb} value to an openHAB-compliant HSB state. | ||
* | ||
* @return color as {@link HSBType} | ||
*/ | ||
public HSBType toHSBType() { | ||
Color color = new Color(rgb); | ||
return HSBType.fromRGB(color.getRed(), color.getGreen(), color.getBlue()); | ||
} | ||
} |
Oops, something went wrong.