Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[deconz] fix colorlight not updating color channel #9351

Merged
merged 2 commits into from Dec 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions bundles/org.openhab.binding.deconz/README.md
Expand Up @@ -89,6 +89,10 @@ The transition time is the time to move between two states and is configured in
The resolution provided is 1/10s.
If no value is provided, the default value of the device is used.

`extendedcolorlight` and `colorlight` have different modes for setting the color.
Some devices accept only XY, others HSB, others both modes and the binding tries to autodetect the correct mode.
If this fails, the advanced `colormode` parameter can be set to `xy` or `hs`.

### Textual Thing Configuration - Retrieving an API Key

If you use the textual configuration, the thing file without an API key will look like this, for example:
Expand Down
Expand Up @@ -78,6 +78,7 @@ public class LightThingHandler extends DeconzBaseThingHandler {
*/
private LightState lightStateCache = new LightState();
private LightState lastCommand = new LightState();
private String colorMode = "";

// set defaults, we can override them later if we receive better values
private int ctMax = ZCL_CT_MAX;
Expand Down Expand Up @@ -179,7 +180,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
} else if (command instanceof HSBType) {
HSBType hsbCommand = (HSBType) command;
if ("xy".equals(lightStateCache.colormode)) {
if ("xy".equals(colorMode)) {
PercentType[] xy = hsbCommand.toXY();
if (xy.length < 2) {
logger.warn("Failed to convert {} to xy-values", command);
Expand Down Expand Up @@ -268,6 +269,7 @@ protected void processStateResponse(DeconzBaseMessage stateResponse) {
}

LightMessage lightMessage = (LightMessage) stateResponse;

if (needsPropertyUpdate) {
// if we did not receive an ctmin/ctmax, then we probably don't need it
needsPropertyUpdate = false;
Expand Down Expand Up @@ -426,6 +428,13 @@ public void messageReceived(String sensorID, DeconzBaseMessage message) {
logger.trace("Ignoring differing update after last command until {}", lastCommandExpireTimestamp);
return;
}
if (colorMode.isEmpty()) {
String cmode = lightState.colormode;
if (cmode != null && ("hs".equals(cmode) || "xy".equals(cmode))) {
// only set the color mode if it is hs or xy, not ct
colorMode = cmode;
}
}
lightStateCache = lightState;
if (Boolean.TRUE.equals(lightState.reachable)) {
updateStatus(ThingStatus.ONLINE);
Expand Down
Expand Up @@ -25,4 +25,5 @@ public class ThingConfig {
public String id = "";
public int lastSeenPolling = 1440;
public @Nullable Double transitiontime;
public String colormode = "";
}
Expand Up @@ -47,7 +47,6 @@
</parameter>
</config-description>


<config-description uri="thing-type:deconz:light">
<parameter name="id" type="text" required="true">
<label>Device ID</label>
Expand All @@ -59,4 +58,24 @@
</parameter>
</config-description>

<config-description uri="thing-type:deconz:colorlight">
<parameter name="id" type="text" required="true">
<label>Device ID</label>
<description>The deCONZ bridge assigns an integer number ID to each device.</description>
</parameter>
<parameter name="transitiontime" type="decimal" required="false" min="0" unit="s">
<label>Transition Time</label>
<description>Time to move between two states. If empty, the default of the device is used. Resolution is 1/10 second.</description>
</parameter>
<parameter name="colormode" type="text" required="false">
<label>Color Mode</label>
<description>Override the default color mode (auto-detect)</description>
<options>
<option value="hs">HSB</option>
<option value="xy">XY</option>
</options>
<advanced>true</advanced>
</parameter>
</config-description>

</config-description:config-descriptions>
Expand Up @@ -97,7 +97,7 @@

<representation-property>uid</representation-property>

<config-description-ref uri="thing-type:deconz:light"/>
<config-description-ref uri="thing-type:deconz:colorlight"/>
</thing-type>

<thing-type id="extendedcolorlight">
Expand All @@ -114,7 +114,7 @@

<representation-property>uid</representation-property>

<config-description-ref uri="thing-type:deconz:light"/>
<config-description-ref uri="thing-type:deconz:colorlight"/>
</thing-type>

<thing-type id="doorlock">
Expand Down