Changed default color mode for color commands to XY (#11036)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
ccbc5e7d46
commit
d5e0e4905a
|
@ -89,7 +89,7 @@ The transition time is the time to move between two states and is configured in
|
||||||
The resolution provided is 1/10s.
|
The resolution provided is 1/10s.
|
||||||
If no value is provided, the default value of the device is used.
|
If no value is provided, the default value of the device is used.
|
||||||
|
|
||||||
`extendedcolorlight` and `colorlight` have different modes for setting the color.
|
`extendedcolorlight`, `colorlight` and `lightgroup` 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.
|
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`.
|
If this fails, the advanced `colormode` parameter can be set to `xy` or `hs`.
|
||||||
|
|
||||||
|
|
|
@ -33,14 +33,16 @@ public class GroupAction {
|
||||||
public @Nullable Integer ct;
|
public @Nullable Integer ct;
|
||||||
public double @Nullable [] xy;
|
public double @Nullable [] xy;
|
||||||
public @Nullable String alert;
|
public @Nullable String alert;
|
||||||
|
public @Nullable String colormode;
|
||||||
public @Nullable String effect;
|
public @Nullable String effect;
|
||||||
public @Nullable Integer colorloopspeed;
|
public @Nullable Integer colorloopspeed;
|
||||||
public @Nullable Integer transitiontime;
|
public @Nullable Integer transitiontime;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "GroupAction{" + "on=" + on + ", toggle=" + toggle + ", bri=" + bri + ", hue=" + hue + ", sat=" + sat
|
return "GroupAction{on=" + on + ", toggle=" + toggle + ", bri=" + bri + ", hue=" + hue + ", sat=" + sat
|
||||||
+ ", ct=" + ct + ", xy=" + Arrays.toString(xy) + ", alert='" + alert + '\'' + ", effect='" + effect
|
+ ", ct=" + ct + ", xy=" + Arrays.toString(xy) + ", alert='" + alert + "', colormode='" + colormode
|
||||||
+ '\'' + ", colorloopspeed=" + colorloopspeed + ", transitiontime=" + transitiontime + '}';
|
+ "', effect='" + effect + "', colorloopspeed=" + colorloopspeed + ", transitiontime=" + transitiontime
|
||||||
|
+ "}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ public class GroupThingHandler extends DeconzBaseThingHandler {
|
||||||
|
|
||||||
private Map<String, String> scenes = Map.of();
|
private Map<String, String> scenes = Map.of();
|
||||||
private GroupState groupStateCache = new GroupState();
|
private GroupState groupStateCache = new GroupState();
|
||||||
|
private String colorMode = "";
|
||||||
|
|
||||||
public GroupThingHandler(Thing thing, Gson gson,
|
public GroupThingHandler(Thing thing, Gson gson,
|
||||||
DeconzDynamicCommandDescriptionProvider commandDescriptionProvider) {
|
DeconzDynamicCommandDescriptionProvider commandDescriptionProvider) {
|
||||||
|
@ -66,6 +67,14 @@ public class GroupThingHandler extends DeconzBaseThingHandler {
|
||||||
this.commandDescriptionProvider = commandDescriptionProvider;
|
this.commandDescriptionProvider = commandDescriptionProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
ThingConfig thingConfig = getConfigAs(ThingConfig.class);
|
||||||
|
colorMode = thingConfig.colormode;
|
||||||
|
|
||||||
|
super.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
String channelId = channelUID.getId();
|
String channelId = channelUID.getId();
|
||||||
|
@ -89,11 +98,17 @@ public class GroupThingHandler extends DeconzBaseThingHandler {
|
||||||
case CHANNEL_COLOR:
|
case CHANNEL_COLOR:
|
||||||
if (command instanceof HSBType) {
|
if (command instanceof HSBType) {
|
||||||
HSBType hsbCommand = (HSBType) command;
|
HSBType hsbCommand = (HSBType) command;
|
||||||
Integer bri = Util.fromPercentType(hsbCommand.getBrightness());
|
// XY color is the implicit default: Use XY color mode if i) no color mode is set or ii) if the bulb
|
||||||
newGroupAction.bri = bri;
|
// is in CT mode or iii) already in XY mode. Only if the bulb is in HS mode, use this one.
|
||||||
if (bri > 0) {
|
if ("hs".equals(colorMode)) {
|
||||||
newGroupAction.hue = (int) (hsbCommand.getHue().doubleValue() * HUE_FACTOR);
|
newGroupAction.hue = (int) (hsbCommand.getHue().doubleValue() * HUE_FACTOR);
|
||||||
newGroupAction.sat = Util.fromPercentType(hsbCommand.getSaturation());
|
newGroupAction.sat = Util.fromPercentType(hsbCommand.getSaturation());
|
||||||
|
} else {
|
||||||
|
PercentType[] xy = hsbCommand.toXY();
|
||||||
|
if (xy.length < 2) {
|
||||||
|
logger.warn("Failed to convert {} to xy-values", command);
|
||||||
|
}
|
||||||
|
newGroupAction.xy = new double[] { xy[0].doubleValue() / 100.0, xy[1].doubleValue() / 100.0 };
|
||||||
}
|
}
|
||||||
} else if (command instanceof PercentType) {
|
} else if (command instanceof PercentType) {
|
||||||
newGroupAction.bri = Util.fromPercentType((PercentType) command);
|
newGroupAction.bri = Util.fromPercentType((PercentType) command);
|
||||||
|
@ -172,6 +187,16 @@ public class GroupThingHandler extends DeconzBaseThingHandler {
|
||||||
thing.getChannels().stream().map(c -> c.getUID().getId()).forEach(c -> valueUpdated(c, groupState));
|
thing.getChannels().stream().map(c -> c.getUID().getId()).forEach(c -> valueUpdated(c, groupState));
|
||||||
groupStateCache = groupState;
|
groupStateCache = groupState;
|
||||||
}
|
}
|
||||||
|
GroupAction groupAction = groupMessage.action;
|
||||||
|
if (groupAction != null) {
|
||||||
|
if (colorMode.isEmpty()) {
|
||||||
|
String cmode = groupAction.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,19 +210,19 @@ public class LightThingHandler extends DeconzBaseThingHandler {
|
||||||
}
|
}
|
||||||
} else if (command instanceof HSBType) {
|
} else if (command instanceof HSBType) {
|
||||||
HSBType hsbCommand = (HSBType) command;
|
HSBType hsbCommand = (HSBType) command;
|
||||||
if ("xy".equals(colorMode)) {
|
// XY color is the implicit default: Use XY color mode if i) no color mode is set or ii) if the bulb
|
||||||
|
// is in CT mode or iii) already in XY mode. Only if the bulb is in HS mode, use this one.
|
||||||
|
if ("hs".equals(colorMode)) {
|
||||||
|
newLightState.hue = (int) (hsbCommand.getHue().doubleValue() * HUE_FACTOR);
|
||||||
|
newLightState.sat = Util.fromPercentType(hsbCommand.getSaturation());
|
||||||
|
} else {
|
||||||
PercentType[] xy = hsbCommand.toXY();
|
PercentType[] xy = hsbCommand.toXY();
|
||||||
if (xy.length < 2) {
|
if (xy.length < 2) {
|
||||||
logger.warn("Failed to convert {} to xy-values", command);
|
logger.warn("Failed to convert {} to xy-values", command);
|
||||||
}
|
}
|
||||||
newLightState.xy = new double[] { xy[0].doubleValue() / 100.0, xy[1].doubleValue() / 100.0 };
|
newLightState.xy = new double[] { xy[0].doubleValue() / 100.0, xy[1].doubleValue() / 100.0 };
|
||||||
newLightState.bri = Util.fromPercentType(hsbCommand.getBrightness());
|
|
||||||
} else {
|
|
||||||
// default is colormode "hs" (used when colormode "hs" is set or colormode is unknown)
|
|
||||||
newLightState.bri = Util.fromPercentType(hsbCommand.getBrightness());
|
|
||||||
newLightState.hue = (int) (hsbCommand.getHue().doubleValue() * HUE_FACTOR);
|
|
||||||
newLightState.sat = Util.fromPercentType(hsbCommand.getSaturation());
|
|
||||||
}
|
}
|
||||||
|
newLightState.bri = Util.fromPercentType(hsbCommand.getBrightness());
|
||||||
} else if (command instanceof PercentType) {
|
} else if (command instanceof PercentType) {
|
||||||
newLightState.bri = Util.fromPercentType((PercentType) command);
|
newLightState.bri = Util.fromPercentType((PercentType) command);
|
||||||
} else if (command instanceof DecimalType) {
|
} else if (command instanceof DecimalType) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.eclipse.jdt.annotation.Nullable;
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class ThingConfig {
|
public class ThingConfig {
|
||||||
public String id = "";
|
public String id = "";
|
||||||
public int lastSeenPolling = 1440;
|
|
||||||
public @Nullable Double transitiontime;
|
public @Nullable Double transitiontime;
|
||||||
public String colormode = "";
|
public String colormode = "";
|
||||||
|
public int lastSeenPolling = 1440;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,23 +10,23 @@
|
||||||
<context>network-address</context>
|
<context>network-address</context>
|
||||||
<description>IP address or host name of deCONZ interface.</description>
|
<description>IP address or host name of deCONZ interface.</description>
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="httpPort" type="integer" required="false" min="1" max="65535">
|
<parameter name="httpPort" type="integer" min="1" max="65535">
|
||||||
<label>HTTP Port</label>
|
<label>HTTP Port</label>
|
||||||
<description>Port of the deCONZ HTTP interface.</description>
|
<description>Port of the deCONZ HTTP interface.</description>
|
||||||
<default>80</default>
|
<default>80</default>
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="port" type="integer" required="false" min="1" max="65535">
|
<parameter name="port" type="integer" min="1" max="65535">
|
||||||
<label>Websocket Port</label>
|
<label>Websocket Port</label>
|
||||||
<description>Port of the deCONZ Websocket.</description>
|
<description>Port of the deCONZ Websocket.</description>
|
||||||
<advanced>true</advanced>
|
<advanced>true</advanced>
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="apikey" type="text" required="false">
|
<parameter name="apikey" type="text">
|
||||||
<label>API Key</label>
|
<label>API Key</label>
|
||||||
<context>password</context>
|
<context>password</context>
|
||||||
<description>If no API Key is provided, a new one will be requested. You need to authorize the access on the deCONZ
|
<description>If no API Key is provided, a new one will be requested. You need to authorize the access on the deCONZ
|
||||||
web interface.</description>
|
web interface.</description>
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="timeout" type="integer" required="false" unit="ms" min="0">
|
<parameter name="timeout" type="integer" unit="ms" min="0">
|
||||||
<label>Timeout</label>
|
<label>Timeout</label>
|
||||||
<description>Timeout for asynchronous HTTP requests (in milliseconds).</description>
|
<description>Timeout for asynchronous HTTP requests (in milliseconds).</description>
|
||||||
<advanced>true</advanced>
|
<advanced>true</advanced>
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
<label>Device ID</label>
|
<label>Device ID</label>
|
||||||
<description>The deCONZ bridge assigns an integer number ID to each device.</description>
|
<description>The deCONZ bridge assigns an integer number ID to each device.</description>
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="transitiontime" type="decimal" required="false" min="0" unit="s">
|
<parameter name="transitiontime" type="decimal" min="0" unit="s">
|
||||||
<label>Transition Time</label>
|
<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>
|
<description>Time to move between two states. If empty, the default of the device is used. Resolution is 1/10 second.</description>
|
||||||
</parameter>
|
</parameter>
|
||||||
|
@ -63,11 +63,11 @@
|
||||||
<label>Device ID</label>
|
<label>Device ID</label>
|
||||||
<description>The deCONZ bridge assigns an integer number ID to each device.</description>
|
<description>The deCONZ bridge assigns an integer number ID to each device.</description>
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="transitiontime" type="decimal" required="false" min="0" unit="s">
|
<parameter name="transitiontime" type="decimal" min="0" unit="s">
|
||||||
<label>Transition Time</label>
|
<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>
|
<description>Time to move between two states. If empty, the default of the device is used. Resolution is 1/10 second.</description>
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="colormode" type="text" required="false">
|
<parameter name="colormode" type="text">
|
||||||
<label>Color Mode</label>
|
<label>Color Mode</label>
|
||||||
<description>Override the default color mode (auto-detect)</description>
|
<description>Override the default color mode (auto-detect)</description>
|
||||||
<options>
|
<options>
|
||||||
|
@ -78,4 +78,19 @@
|
||||||
</parameter>
|
</parameter>
|
||||||
</config-description>
|
</config-description>
|
||||||
|
|
||||||
|
<config-description uri="thing-type:deconz:lightgroup">
|
||||||
|
<parameter name="id" type="text" required="true">
|
||||||
|
<label>Device ID</label>
|
||||||
|
<description>The deCONZ bridge assigns an integer number ID to each group.</description>
|
||||||
|
</parameter>
|
||||||
|
<parameter name="colormode" type="text">
|
||||||
|
<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>
|
</config-description:config-descriptions>
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
<representation-property>uid</representation-property>
|
<representation-property>uid</representation-property>
|
||||||
|
|
||||||
<config-description-ref uri="thing-type:deconz:sensor"/>
|
<config-description-ref uri="thing-type:deconz:lightgroup"/>
|
||||||
</thing-type>
|
</thing-type>
|
||||||
|
|
||||||
<channel-type id="all_on">
|
<channel-type id="all_on">
|
||||||
|
|
Loading…
Reference in New Issue