Skip to content

Commit

Permalink
close openhab#7 close openhab#18 Add extra actions to set white color…
Browse files Browse the repository at this point in the history
… and turn off RGB lights
  • Loading branch information
magx2 committed May 15, 2019
1 parent 2ac7435 commit f5002ca
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ public static class Channels {
public static final String TEMPERATURE_AND_HUMIDITY_CHANNEL_ID = "temperature-and-humidity-channel";
public static final String DIMMER_CHANNEL_ID = "dimmer-channel";
public static final String TOGGLE_GAT_CHANNEL_ID = "toggle-gate-channel";
public static final String EXTRA_LIGHT_ACTIONS_CHANNEL_ID = "extra-light-actions-channel";
public static final String UNKNOWN_CHANNEL_ID = "unknown-channel";
}

public static class Commands {
public static final String OPEN_CLOSE_GATE_COMMAND = "open-close";
public static final String WHITE_LIGHT_COMMAND = "light-white";
public static final String OFF_LIGHT_COMMAND = "light-off";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@
import static org.eclipse.smarthome.core.thing.ThingStatusDetail.CONFIGURATION_ERROR;
import static org.eclipse.smarthome.core.thing.ThingStatusDetail.NONE;
import static org.eclipse.smarthome.core.types.RefreshType.REFRESH;
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.OFF_LIGHT_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.OPEN_CLOSE_GATE_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.Commands.WHITE_LIGHT_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.SUPLA_DEVICE_CLOUD_ID;
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.EXTRA_LIGHT_ACTIONS;
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.LED_BRIGHTNESS;
import static org.openhab.binding.supla.internal.cloud.ChannelFunctionDispatcher.DISPATCHER;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.CLOSE;
Expand Down Expand Up @@ -333,9 +336,25 @@ protected void handleStringCommand(final ChannelUID channelUID, final StringType
if (command.toFullString().equals(OPEN_CLOSE_GATE_COMMAND)) {
final ChannelExecuteActionRequest action = new ChannelExecuteActionRequest().action(OPEN_CLOSE);
channelsApi.executeAction(action, channelId);
} else if (EXTRA_LIGHT_ACTIONS.equals(channelInfo.getAdditionalChannelType())) {
final ChannelUID mainLightChannel = new ChannelUID(channelUID.getThingUID(), String.valueOf(channelId));
if (command.toFullString().equals(WHITE_LIGHT_COMMAND)) {
changeColorOfRgb(HSBType.WHITE, mainLightChannel);
} else if (command.toFullString().equals(OFF_LIGHT_COMMAND)) {
changeColorOfRgb(HSBType.BLACK, mainLightChannel);
}
} else {
logger.warn("Not handling `{}` ({}) on channel `{}`", command, command.getClass().getSimpleName(), channelUID);
}
}

private void changeColorOfRgb(HSBType hsbType, ChannelUID rgbChannelUid) throws ApiException {
logger.trace("Setting color to `{}` for channel `{}`", hsbType, rgbChannelUid);
handleHsbCommand(rgbChannelUid, hsbType);
updateState(rgbChannelUid, hsbType);
handleCommand(rgbChannelUid, REFRESH);
}

void refresh() {
logger.debug("Refreshing `{}`", thing.getUID());
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.openhab.binding.supla.internal.cloud;

public enum AdditionalChannelType {
LED_BRIGHTNESS("_brightness");
LED_BRIGHTNESS("_brightness"), EXTRA_LIGHT_ACTIONS("_extra_light_actions");

private final String suffix;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ private int parse(String id, String fullId) {
}
}
}
// ZjA0MWIwZWZmYWE5MTEzZGM3NDU3NjZjZDQ1ZTA3MTNjNGViNDUzOGYyNGQ3NjU2YTc5NGZkMTkzZjIzOTBhYQ.aHR0cHM6Ly9zdnIxOS5zdXBsYS5vcmc=
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import java.util.List;

import static com.google.common.base.Strings.isNullOrEmpty;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.DECIMAL_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.DIMMER_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.EXTRA_LIGHT_ACTIONS_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.HUMIDITY_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.LIGHT_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.RGB_CHANNEL_ID;
Expand All @@ -28,6 +30,7 @@
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.TEMPERATURE_AND_HUMIDITY_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.TEMPERATURE_CHANNEL_ID;
import static org.openhab.binding.supla.SuplaBindingConstants.Channels.TOGGLE_GAT_CHANNEL_ID;
import static org.openhab.binding.supla.internal.cloud.AdditionalChannelType.EXTRA_LIGHT_ACTIONS;

@SuppressWarnings("PackageAccessibility")
public class CreateChannelFunctionSwitch implements ChannelFunctionDispatcher.FunctionSwitch<List<Channel>> {
Expand Down Expand Up @@ -235,6 +238,8 @@ private List<Channel> createToggleGateChannel(pl.grzeslowski.jsupla.api.generate
}

private List<Channel> createLedChannels(final pl.grzeslowski.jsupla.api.generated.model.Channel channel) {
return singletonList(createChannel(channel, RGB_CHANNEL_ID, "Color"));
return asList(
createChannel(channel, RGB_CHANNEL_ID, "Color"),
createChannel(EXTRA_LIGHT_ACTIONS_CHANNEL_ID, "String", channel.getId() + EXTRA_LIGHT_ACTIONS.getSuffix(), "Extra Actions"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@
</command>
</channel-type>

<channel-type id="extra-light-actions-channel">
<item-type>String</item-type>
<label>Quick Actions</label>
<command>
<options>
<option value="light-white">Set White</option>
<option value="light-off">Turn OFF</option>
</options>
</command>
</channel-type>

<channel-type id="unknown-channel">
<item-type>String</item-type>
<label>Unknown channel</label>
Expand Down

0 comments on commit f5002ca

Please sign in to comment.