use of org.openhab.binding.deconz.internal.dto.GroupAction in project openhab-addons by openhab.
the class GroupThingHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
String channelId = channelUID.getId();
GroupAction newGroupAction = new GroupAction();
switch(channelId) {
case CHANNEL_ALL_ON:
case CHANNEL_ANY_ON:
if (command instanceof RefreshType) {
valueUpdated(channelUID.getId(), groupStateCache);
return;
}
break;
case CHANNEL_ALERT:
if (command instanceof StringType) {
newGroupAction.alert = command.toString();
} else {
return;
}
break;
case CHANNEL_COLOR:
if (command instanceof HSBType) {
HSBType hsbCommand = (HSBType) command;
// 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)) {
newGroupAction.hue = (int) (hsbCommand.getHue().doubleValue() * HUE_FACTOR);
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) {
newGroupAction.bri = Util.fromPercentType((PercentType) command);
} else if (command instanceof DecimalType) {
newGroupAction.bri = ((DecimalType) command).intValue();
} else if (command instanceof OnOffType) {
newGroupAction.on = OnOffType.ON.equals(command);
} else {
return;
}
break;
case CHANNEL_COLOR_TEMPERATURE:
if (command instanceof DecimalType) {
int miredValue = Util.kelvinToMired(((DecimalType) command).intValue());
newGroupAction.ct = Util.constrainToRange(miredValue, ZCL_CT_MIN, ZCL_CT_MAX);
} else {
return;
}
break;
case CHANNEL_SCENE:
if (command instanceof StringType) {
String sceneId = scenes.get(command.toString());
if (sceneId != null) {
sendCommand(null, command, channelUID, "scenes/" + sceneId + "/recall", null);
} else {
logger.debug("Ignoring command {} for {}, scene is not found in available scenes: {}", command, channelUID, scenes);
}
}
return;
default:
return;
}
Integer bri = newGroupAction.bri;
if (bri != null) {
newGroupAction.on = (bri > 0);
}
sendCommand(newGroupAction, command, channelUID, null);
}
use of org.openhab.binding.deconz.internal.dto.GroupAction in project openhab-addons by openhab.
the class GroupThingHandler method messageReceived.
@Override
public void messageReceived(String sensorID, DeconzBaseMessage message) {
if (message instanceof GroupMessage) {
GroupMessage groupMessage = (GroupMessage) message;
logger.trace("{} received {}", thing.getUID(), groupMessage);
GroupState groupState = groupMessage.state;
if (groupState != null) {
updateStatus(ThingStatus.ONLINE);
thing.getChannels().stream().map(c -> c.getUID().getId()).forEach(c -> valueUpdated(c, 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;
}
}
}
}
}
Aggregations