diff --git a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/SuplaBindingConstants.java b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/SuplaBindingConstants.java index d24979cbc431c..daaf13e69e029 100644 --- a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/SuplaBindingConstants.java +++ b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/SuplaBindingConstants.java @@ -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"; + } } diff --git a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/AbstractDeviceHandler.java b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/AbstractDeviceHandler.java index 4a662fa81f14c..bf6c090f8dcf6 100644 --- a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/AbstractDeviceHandler.java +++ b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/AbstractDeviceHandler.java @@ -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; @@ -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); @@ -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; } diff --git a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/CloudDeviceHandler.java b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/CloudDeviceHandler.java index d30951706663e..26150fc6906f6 100644 --- a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/CloudDeviceHandler.java +++ b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/CloudDeviceHandler.java @@ -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; @@ -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; @@ -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 { diff --git a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/SuplaDeviceHandler.java b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/SuplaDeviceHandler.java index 4cd7f14af8dcd..7131351856c6d 100644 --- a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/SuplaDeviceHandler.java +++ b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/handler/SuplaDeviceHandler.java @@ -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; @@ -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) {