Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
104712e
Create LightUtil.java
andrewfg Aug 29, 2025
caf4219
javadoc and min/max code style
andrewfg Aug 29, 2025
64c68d9
spotless
andrewfg Aug 29, 2025
ed4f05c
fix javadoc errors
andrewfg Aug 29, 2025
f50fa22
use quantitytype for color temperatures
andrewfg Aug 29, 2025
4d591f1
refactoring
andrewfg Aug 29, 2025
12299f6
bug fix
andrewfg Aug 29, 2025
3509a44
Create LightStateMachine.java
andrewfg Aug 30, 2025
1fbc5db
Merge remote-tracking branch 'upstream/main' into light-helpers
andrewfg Aug 30, 2025
875e6c7
work in progress
andrewfg Aug 30, 2025
5aab892
unit tests and refactoring
andrewfg Aug 30, 2025
931dcf1
refactoring and testing
andrewfg Aug 31, 2025
1d2edc0
fix typos
andrewfg Aug 31, 2025
4ec5a81
Merge branch 'openhab:main' into light-helpers
andrewfg Aug 31, 2025
ce30be9
fix typos
andrewfg Aug 31, 2025
e0d9c11
various
andrewfg Sep 1, 2025
95db4ad
tweaks to javadoc
andrewfg Sep 1, 2025
774d6db
fix javadoc build error
andrewfg Sep 1, 2025
aa04db2
remove more bad link fields
andrewfg Sep 1, 2025
7d46b42
implement OH sparse channel policy
andrewfg Sep 1, 2025
f53b895
Update bundles/org.openhab.core/src/main/java/org/openhab/core/util/L…
andrewfg Sep 1, 2025
10ab72c
Update bundles/org.openhab.core/src/main/java/org/openhab/core/util/L…
andrewfg Sep 1, 2025
2dc69ab
Update bundles/org.openhab.core/src/main/java/org/openhab/core/util/L…
andrewfg Sep 1, 2025
61846cd
fix spotless and copilot suggestions
andrewfg Sep 1, 2025
7e4d837
rename methods
andrewfg Sep 1, 2025
7ec362a
first stab at RGBCW support
andrewfg Sep 1, 2025
e3d2544
fix javadoc issues
andrewfg Sep 1, 2025
8bc9750
multiple fixes
andrewfg Sep 2, 2025
6e1a1e1
fix javadoc error
andrewfg Sep 2, 2025
3dbedd1
rework RGBCW and tests; refactor into one class
andrewfg Sep 2, 2025
e97fddb
more javadoc stuff
andrewfg Sep 2, 2025
d115ef6
fix copilot suggestions
andrewfg Sep 2, 2025
71c6702
add TODO for RGBCW JUnit test cases
andrewfg Sep 2, 2025
8966895
RGBCW tests and fixes
andrewfg Sep 3, 2025
de8f1d5
fix javadoc error
andrewfg Sep 3, 2025
78af403
Update bundles/org.openhab.core/src/main/java/org/openhab/core/util/L…
andrewfg Sep 3, 2025
39266a6
refactor RGBCW; write correct unit tests
andrewfg Sep 6, 2025
211abd4
refactor RgbcwMath for possible move to ColorUtil
andrewfg Sep 7, 2025
2a89dd1
fix javadoc and typo
andrewfg Sep 7, 2025
170d591
simplify rgb data type configuration
andrewfg Sep 7, 2025
8d958cc
fix javadoc link fields
andrewfg Sep 7, 2025
76aa10d
adopt copilot suggestions
andrewfg Sep 7, 2025
3f31050
improve rgb to rgbcw conversion
andrewfg Sep 8, 2025
3519450
Update bundles/org.openhab.core/src/main/java/org/openhab/core/util/L…
andrewfg Sep 8, 2025
330f396
Update bundles/org.openhab.core/src/main/java/org/openhab/core/util/L…
andrewfg Sep 8, 2025
05c4076
adopt copilot suggestion about comparing enums
andrewfg Sep 8, 2025
beb0b3c
Update bundles/org.openhab.core/src/main/java/org/openhab/core/util/L…
andrewfg Sep 8, 2025
bd55090
adopt more copilot suggestions
andrewfg Sep 8, 2025
fa67275
tweak
andrewfg Sep 8, 2025
d683058
add BaseLightThingHandler prototype
andrewfg Sep 8, 2025
9c2a779
javadoc and copilot stuff
andrewfg Sep 8, 2025
3182226
Update bundles/org.openhab.core/src/main/java/org/openhab/core/util/L…
andrewfg Sep 8, 2025
2987971
typos; javadoc; clone method
andrewfg Sep 8, 2025
aa5093b
adopt reviewer suggestions
andrewfg Sep 10, 2025
63e0623
fix javadoc
andrewfg Sep 10, 2025
3b05f61
Merge remote-tracking branch 'upstream/main' into light-helpers
andrewfg Oct 9, 2025
4598e5a
support various led operating modes; add javadoc
andrewfg Oct 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/*
* Copyright (c) 2010-2025 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.core.thing.binding;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.types.Command;
import org.openhab.core.util.LightModel;

/**
* {@link BaseLightThingHandler} provides an abstract base implementation for a {@link ThingHandler} for a light.
*
* @author Andrew Fiddian-Green - Initial contribution
*/
@NonNullByDefault
public abstract class BaseLightThingHandler extends BaseThingHandler {

/**
* Light state machine model to manage light capabilities, configuration, and runtime state
*/
private final LightModel model = new LightModel();

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

/**
* Override this method to handle commands from OH core.
* <p>
* Example: (implementation will depend on the specific binding and device).
*
* <pre>
* {@code
*
* // update the model state based on the command from OpenHAB
* model.handleCommand(command);
*
* // or if it is a color temperature command
* model.handleColorTemperatureCommand(command);
*
* // and transmit the appropriate command to the remote light device based on the model state
* doTransmitBindingSpecificRemoteLightData(model);
*
* }
* </pre>
*/
@Override
public abstract void handleCommand(ChannelUID channelUID, Command command);

/**
* Override this method to provide initialization of the light state machine capabilities and configuration
* parameters.
* <p>
* Example: (implementation will depend on the specific binding and device).
*
* <pre>
* {@code
*
* // STEP 1: Set up the light state machine capabilities.
* model.configSetLightCapabilities(LightCapabilities.COLOR_WITH_COLOR_TEMPERATURE);
*
* // STEP 2: optionally set up the light state machine configuration parameters.
* // These would typically be read from the thing configuration or read from the remote device.
* model.configSetRgbDataType(RgbDataType.RGB_NO_BRIGHTNESS); // RGB data type
* model.configSetMinimumOnBrightness(2); // minimum brightness level in % when on
* model.configSetIncreaseDecreaseStep(10); // step size for increase/decrease commands
* model.configSetMiredControlCoolest(153); // color temperature control range coolest
* model.configSetMiredControlWarmest(500); // color temperature control range warmest
*
* // STEP 3: optionally if the light has warm and cool white LEDS then set up their LED color temperatures.
* // These would typically be read from the thing configuration or read from the remote device.
* model.configSetMiredCoolWhiteLED(153);
* model.configSetMiredWarmWhiteLED(500);
*
* // STEP 4: now set the status to UNKNOWN to indicate that we are initialized
* updateStatus(ThingStatus.UNKNOWN);
*
* // STEP 5: finally provide further initialization, e.g. connecting to the remote device
* ...
*
* }
* </pre>
*/
@Override
public abstract void initialize();

/**
* Transmit the appropriate command to the remote light device based on the model state.
* This method must be overridden in the concrete implementation to transmit the appropriate command(s)
* to the remote light device based on the model state.
* <p>
* Example: (implementation will depend on the specific binding and device).
*
* <pre>
* {@code
*
* if (model.getOnOff() == OnOffType.ON) {
* transmit command to turn on the light
* } else {
* transmit command to turn off the light
* }
*
* if (model.getBrightness() != null) {
* transmit command to set brightness to model.getBrightness()
* }
*
* if (model.getColor() != null) {
* transmit command to set color to model.getColor()
* }
*
* if (model.getColorTemperature() != null) {
* transmit command to set color temperature to model.getColorTemperature()
* }
*
* if (model.getColorTemperaturePercent() != null) {
* transmit command to set color temperature percent to model.getColorTemperaturePercent()
* }
*
* if (model.getRGBx().length == 3) {
* transmit command to set RGB value to model.getRGBx()
* }
*
* if (model.getXY() != null) {
* transmit command to set XY value to model.getXY()
* }
* }
* </pre>
*
* @param model the light model containing the current state
*/
protected abstract void doTransmitBindingSpecificRemoteLightData(LightModel model);

/**
* Receive data from the remote light device and update the model state accordingly.
* This method must be overridden in the concrete implementation to 1) receive data from the remote light device
* 2) update the model state accordingly, and 3) update the openHAB channels.
* <P>
* Example: (implementation will depend on the specific binding and device).
*
* <pre>
* {@code
*
* STEP 1: Parse the remoteData to extract the relevant information. Depends on specific binding / device
*
* OnOffType onOff = ...; // extract on/off state from remoteData
* Integer brightness = ...; // extract brightness from remoteData
* HSBType color = ...; // extract color from remoteData
* Integer colorTemperature = ...; // extract color temperature from remoteData
* Integer colorTemperaturePercent = ...; // extract color temperature percent from remoteData
* RGBType rgb = ...; // extract RGB value from remoteData
* XYType xy = ...; // extract XY value from remoteData
*
* STEP 2: Update the model state based on the received data
*
* if (onOff != null) {
* model.setOnOff(onOff);
* }
*
* if (brightness != null) {
* model.setBrightness(brightness);
* }
*
* if (color != null) {
* model.setColor(color);
* }
*
* if (colorTemperature != null) {
* model.setColorTemperature(colorTemperature);
* }
*
* if (colorTemperaturePercent != null) {
* model.setColorTemperaturePercent(colorTemperaturePercent);
* }
*
* if (rgb != null) {
* model.setRGBx(rgb);
* }
*
* if (xy != null) {
* model.setXY(xy);
* }
*
* STEP 3: After updating the model, update the channel states in OpenHAB
* Note: Ensure that the channel IDs used in updateState() match those defined in the thing type.
*
* if (model.configGetLightCapabilities().supportsColor()) {
* updateState(CHANNEL_COLOR, model.getColor());
* } else if (model.configGetLightCapabilities().supportsBrightness()) {
* updateState(CHANNEL_BRIGHTNESS, model.getBrightness());
* } else {
* updateState(CHANNEL_ON_OFF, model.getOnOff());
* }
*
* if (model.configGetLightCapabilities().supportsColorTemperature()) {
* updateState(CHANNEL_COLOR_TEMPERATURE_ABS, model.getColorTemperature());
* updateState(CHANNEL_COLOR_TEMPERATURE_PERCENT, model.getColorTemperaturePercent());
* }
* }
* </pre>
*
* @param remoteData the data received from the remote light device
*/
protected abstract void onReceiveBindingSpecificRemoteLightData(Object... remoteData);
}
Loading