From f5002cad5c9c876fd01d6816a9ce3c1012441e08 Mon Sep 17 00:00:00 2001 From: Martin Grzeslowski Date: Wed, 15 May 2019 19:23:11 +0200 Subject: [PATCH] close #7 close #18 Add extra actions to set white color and turn off RGB lights --- .../binding/supla/SuplaBindingConstants.java | 3 +++ .../supla/handler/CloudDeviceHandler.java | 19 +++++++++++++++++++ .../internal/cloud/AdditionalChannelType.java | 2 +- .../internal/cloud/ChannelIfoParser.java | 1 - .../CreateChannelFunctionSwitch.java | 7 ++++++- .../resources/ESH-INF/thing/thing-types.xml | 11 +++++++++++ 6 files changed, 40 insertions(+), 3 deletions(-) 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 daaf13e69e029..a7f76a4f0d71e 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 @@ -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"; } } 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 26150fc6906f6..c32b58f4f7a3a 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 @@ -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; @@ -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 { diff --git a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/AdditionalChannelType.java b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/AdditionalChannelType.java index ab5d5fd7fce27..63518623dced4 100644 --- a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/AdditionalChannelType.java +++ b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/AdditionalChannelType.java @@ -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; diff --git a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/ChannelIfoParser.java b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/ChannelIfoParser.java index 8978cb7229007..581291b4090d1 100644 --- a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/ChannelIfoParser.java +++ b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/ChannelIfoParser.java @@ -33,4 +33,3 @@ private int parse(String id, String fullId) { } } } -// ZjA0MWIwZWZmYWE5MTEzZGM3NDU3NjZjZDQ1ZTA3MTNjNGViNDUzOGYyNGQ3NjU2YTc5NGZkMTkzZjIzOTBhYQ.aHR0cHM6Ly9zdnIxOS5zdXBsYS5vcmc= \ No newline at end of file diff --git a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/functionswitch/CreateChannelFunctionSwitch.java b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/functionswitch/CreateChannelFunctionSwitch.java index 3128efdc955a1..6602e721bbef1 100644 --- a/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/functionswitch/CreateChannelFunctionSwitch.java +++ b/bundles/org.openhab.binding.supla/src/main/java/org/openhab/binding/supla/internal/cloud/functionswitch/CreateChannelFunctionSwitch.java @@ -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; @@ -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> { @@ -235,6 +238,8 @@ private List createToggleGateChannel(pl.grzeslowski.jsupla.api.generate } private List 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")); } } diff --git a/bundles/org.openhab.binding.supla/src/main/resources/ESH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.supla/src/main/resources/ESH-INF/thing/thing-types.xml index cde3d1c947afc..6413afc5809b6 100644 --- a/bundles/org.openhab.binding.supla/src/main/resources/ESH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.supla/src/main/resources/ESH-INF/thing/thing-types.xml @@ -107,6 +107,17 @@ + + String + + + + + + + + + String