Skip to content

Commit

Permalink
openhab#11 Handle open/close on gate
Browse files Browse the repository at this point in the history
  • Loading branch information
magx2 committed May 15, 2019
1 parent aca0813 commit 2ac7435
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ public static class Channels {
public static final String TOGGLE_GAT_CHANNEL_ID = "toggle-gate-channel";
public static final String UNKNOWN_CHANNEL_ID = "unknown-channel";
}

public static class Commands {
public static final String OPEN_CLOSE_GATE_COMMAND = "open-close";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.eclipse.smarthome.core.library.types.OpenClosedType;
import org.eclipse.smarthome.core.library.types.PercentType;
import org.eclipse.smarthome.core.library.types.StopMoveType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.library.types.UpDownType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
Expand Down Expand Up @@ -59,6 +60,8 @@ public final void handleCommand(final ChannelUID channelUID, final Command comma
handleDecimalCommand(channelUID, (DecimalType) command);
} else if (command instanceof StopMoveType) {
handleStopMoveTypeCommand(channelUID, (StopMoveType) command);
} else if (command instanceof StringType) {
handleStringCommand(channelUID, (StringType) command);
} else {
logger.warn("Does not know how to handle command `{}` ({}) on channel `{}`!",
command, command.getClass().getSimpleName(), channelUID);
Expand All @@ -84,4 +87,6 @@ public final void handleCommand(final ChannelUID channelUID, final Command comma
protected abstract void handleDecimalCommand(@NonNull final ChannelUID channelUID, @NonNull final DecimalType command) throws Exception;

protected abstract void handleStopMoveTypeCommand(@NonNull final ChannelUID channelUID, @NonNull final StopMoveType command) throws Exception;

protected abstract void handleStringCommand(@NonNull final ChannelUID channelUID, @NonNull final StringType command) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.eclipse.smarthome.core.library.types.OpenClosedType;
import org.eclipse.smarthome.core.library.types.PercentType;
import org.eclipse.smarthome.core.library.types.StopMoveType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.library.types.UpDownType;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.Channel;
Expand Down Expand Up @@ -51,11 +52,13 @@
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.OPEN_CLOSE_GATE_COMMAND;
import static org.openhab.binding.supla.SuplaBindingConstants.SUPLA_DEVICE_CLOUD_ID;
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;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.OPEN;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.OPEN_CLOSE;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.REVEAL;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.REVEAL_PARTIALLY;
import static pl.grzeslowski.jsupla.api.generated.model.ChannelFunctionActionEnum.SHUT;
Expand Down Expand Up @@ -323,6 +326,16 @@ private void handleStopMoveTypeCommandOnRollerShutter(
}
}

@Override
protected void handleStringCommand(final ChannelUID channelUID, final StringType command) throws ApiException {
final ChannelInfo channelInfo = ChannelIfoParser.PARSER.parse(channelUID);
final int channelId = channelInfo.getChannelId();
if (command.toFullString().equals(OPEN_CLOSE_GATE_COMMAND)) {
final ChannelExecuteActionRequest action = new ChannelExecuteActionRequest().action(OPEN_CLOSE);
channelsApi.executeAction(action, channelId);
}
}

void refresh() {
logger.debug("Refreshing `{}`", thing.getUID());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.smarthome.core.library.types.OpenClosedType;
import org.eclipse.smarthome.core.library.types.PercentType;
import org.eclipse.smarthome.core.library.types.StopMoveType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.library.types.UpDownType;
import org.eclipse.smarthome.core.thing.Channel;
import org.eclipse.smarthome.core.thing.ChannelUID;
Expand Down Expand Up @@ -152,6 +153,11 @@ protected void handleStopMoveTypeCommand(final @NonNull ChannelUID channelUID, f
logger.warn("Not handling `{}` ({}) on channel `{}`", command, command.getClass().getSimpleName(), channelUID);
}

@Override
protected void handleStringCommand(final ChannelUID channelUID, final StringType command) throws Exception {
logger.warn("Not handling `{}` ({}) on channel `{}`", command, command.getClass().getSimpleName(), channelUID);
}

@Override
protected void internalInitialize() {
if (getBridge() == null) {
Expand Down

0 comments on commit 2ac7435

Please sign in to comment.