diff --git a/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/RawButtonToggleRollershutterProfile.java b/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/RawButtonToggleRollershutterProfile.java new file mode 100644 index 0000000000..521fc5af35 --- /dev/null +++ b/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/RawButtonToggleRollershutterProfile.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2010-2019 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.core.thing.internal.profiles; + +import static org.eclipse.smarthome.core.thing.profiles.SystemProfiles.RAWBUTTON_TOGGLE_ROLLERSHUTTER; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.core.library.types.UpDownType; +import org.eclipse.smarthome.core.thing.CommonTriggerEvents; +import org.eclipse.smarthome.core.thing.profiles.ProfileCallback; +import org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID; +import org.eclipse.smarthome.core.thing.profiles.TriggerProfile; +import org.eclipse.smarthome.core.types.State; + +/** + * This profile allows a channel of the "system:rawbutton" type to be bound to an item. + * + * It reads the triggered events and uses the item's current state and toggles it once it detects that the + * button was pressed. + * + * @author Christoph Weitkamp - Initial contribution + */ +@NonNullByDefault +public class RawButtonToggleRollershutterProfile implements TriggerProfile { + + private final ProfileCallback callback; + + @Nullable + private State previousState; + + public RawButtonToggleRollershutterProfile(ProfileCallback callback) { + this.callback = callback; + } + + @Override + public ProfileTypeUID getProfileTypeUID() { + return RAWBUTTON_TOGGLE_ROLLERSHUTTER; + } + + @Override + public void onTriggerFromHandler(String event) { + if (CommonTriggerEvents.PRESSED.equals(event)) { + UpDownType newState = UpDownType.UP.equals(previousState) ? UpDownType.DOWN : UpDownType.UP; + callback.sendCommand(newState); + previousState = newState; + } + } + + @Override + public void onStateUpdateFromItem(State state) { + previousState = state.as(UpDownType.class); + } + +} diff --git a/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/RawRockerStopMoveProfile.java b/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/RawRockerStopMoveProfile.java new file mode 100644 index 0000000000..239f2c879d --- /dev/null +++ b/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/RawRockerStopMoveProfile.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2010-2019 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.core.thing.internal.profiles; + +import static org.eclipse.smarthome.core.thing.profiles.SystemProfiles.RAWROCKER_STOP_MOVE; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.smarthome.core.library.items.RollershutterItem; +import org.eclipse.smarthome.core.library.types.StopMoveType; +import org.eclipse.smarthome.core.thing.CommonTriggerEvents; +import org.eclipse.smarthome.core.thing.profiles.ProfileCallback; +import org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID; +import org.eclipse.smarthome.core.thing.profiles.TriggerProfile; +import org.eclipse.smarthome.core.types.State; + +/** + * The {@link RawRockerStopMoveProfile} transforms rocker switch channel events into STOP and MOVE commands. Can be used + * on a {@link RollershutterItem}. + * + * @author Christoph Weitkamp - Initial contribution + */ +@NonNullByDefault +public class RawRockerStopMoveProfile implements TriggerProfile { + + private final ProfileCallback callback; + + RawRockerStopMoveProfile(ProfileCallback callback) { + this.callback = callback; + } + + @Override + public ProfileTypeUID getProfileTypeUID() { + return RAWROCKER_STOP_MOVE; + } + + @Override + public void onStateUpdateFromItem(State state) { + } + + @Override + public void onTriggerFromHandler(String event) { + if (CommonTriggerEvents.DIR1_PRESSED.equals(event)) { + callback.sendCommand(StopMoveType.MOVE); + } else if (CommonTriggerEvents.DIR2_PRESSED.equals(event)) { + callback.sendCommand(StopMoveType.STOP); + } + } + +} diff --git a/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/RawRockerUpDownProfile.java b/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/RawRockerUpDownProfile.java new file mode 100644 index 0000000000..c5d61dc45f --- /dev/null +++ b/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/RawRockerUpDownProfile.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2010-2019 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.smarthome.core.thing.internal.profiles; + +import static org.eclipse.smarthome.core.thing.profiles.SystemProfiles.RAWROCKER_UP_DOWN; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.smarthome.core.library.items.RollershutterItem; +import org.eclipse.smarthome.core.library.types.UpDownType; +import org.eclipse.smarthome.core.thing.CommonTriggerEvents; +import org.eclipse.smarthome.core.thing.profiles.ProfileCallback; +import org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID; +import org.eclipse.smarthome.core.thing.profiles.TriggerProfile; +import org.eclipse.smarthome.core.types.State; + +/** + * The {@link RawRockerUpDownProfile} transforms rocker switch channel events into UP and DOWM commands. Can be used on + * a {@link RollershutterItem}. + * + * @author Christoph Weitkamp - Initial contribution + */ +@NonNullByDefault +public class RawRockerUpDownProfile implements TriggerProfile { + + private final ProfileCallback callback; + + RawRockerUpDownProfile(ProfileCallback callback) { + this.callback = callback; + } + + @Override + public ProfileTypeUID getProfileTypeUID() { + return RAWROCKER_UP_DOWN; + } + + @Override + public void onStateUpdateFromItem(State state) { + } + + @Override + public void onTriggerFromHandler(String event) { + if (CommonTriggerEvents.DIR1_PRESSED.equals(event)) { + callback.sendCommand(UpDownType.UP); + } else if (CommonTriggerEvents.DIR2_PRESSED.equals(event)) { + callback.sendCommand(UpDownType.DOWN); + } + } + +} diff --git a/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/SystemProfileFactory.java b/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/SystemProfileFactory.java index a7d21b919a..76a01765c7 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/SystemProfileFactory.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/internal/profiles/SystemProfileFactory.java @@ -55,16 +55,17 @@ public class SystemProfileFactory implements ProfileFactory, ProfileAdvisor, Pro @NonNullByDefault({}) private ChannelTypeRegistry channelTypeRegistry; - private static final Set SUPPORTED_PROFILE_TYPES = Stream.of(DEFAULT_TYPE, FOLLOW_TYPE, OFFSET_TYPE, - RAWBUTTON_TOGGLE_PLAYER_TYPE, RAWBUTTON_TOGGLE_SWITCH_TYPE, RAWROCKER_DIMMER_TYPE, - RAWROCKER_NEXT_PREVIOUS_TYPE, RAWROCKER_ON_OFF_TYPE, RAWROCKER_PLAY_PAUSE_TYPE, - RAWROCKER_REWIND_FASTFORWARD_TYPE, TIMESTAMP_CHANGE_TYPE, TIMESTAMP_UPDATE_TYPE) + private static final Set SUPPORTED_PROFILE_TYPES = Stream + .of(DEFAULT_TYPE, FOLLOW_TYPE, OFFSET_TYPE, RAWBUTTON_TOGGLE_PLAYER_TYPE, RAWBUTTON_TOGGLE_PLAYER_TYPE, + RAWBUTTON_TOGGLE_SWITCH_TYPE, RAWROCKER_DIMMER_TYPE, RAWROCKER_NEXT_PREVIOUS_TYPE, + RAWROCKER_ON_OFF_TYPE, RAWROCKER_PLAY_PAUSE_TYPE, RAWROCKER_REWIND_FASTFORWARD_TYPE, + RAWROCKER_STOP_MOVE_TYPE, RAWROCKER_UP_DOWN_TYPE, TIMESTAMP_CHANGE_TYPE, TIMESTAMP_UPDATE_TYPE) .collect(Collectors.toSet()); private static final Set SUPPORTED_PROFILE_TYPE_UIDS = Stream.of(DEFAULT, FOLLOW, OFFSET, - RAWBUTTON_TOGGLE_PLAYER, RAWBUTTON_TOGGLE_SWITCH, RAWROCKER_DIMMER, RAWROCKER_NEXT_PREVIOUS, - RAWROCKER_ON_OFF, RAWROCKER_PLAY_PAUSE, RAWROCKER_REWIND_FASTFORWARD, TIMESTAMP_CHANGE, TIMESTAMP_UPDATE) - .collect(Collectors.toSet()); + RAWBUTTON_TOGGLE_PLAYER, RAWBUTTON_TOGGLE_PLAYER, RAWBUTTON_TOGGLE_SWITCH, RAWROCKER_DIMMER, + RAWROCKER_NEXT_PREVIOUS, RAWROCKER_ON_OFF, RAWROCKER_PLAY_PAUSE, RAWROCKER_REWIND_FASTFORWARD, + RAWROCKER_STOP_MOVE, RAWROCKER_UP_DOWN, TIMESTAMP_CHANGE, TIMESTAMP_UPDATE).collect(Collectors.toSet()); @Nullable @Override @@ -77,6 +78,8 @@ public class SystemProfileFactory implements ProfileFactory, ProfileAdvisor, Pro return new SystemOffsetProfile(callback, context); } else if (RAWBUTTON_TOGGLE_SWITCH.equals(profileTypeUID)) { return new RawButtonToggleSwitchProfile(callback); + } else if (RAWBUTTON_TOGGLE_PLAYER.equals(profileTypeUID)) { + return new RawButtonToggleRollershutterProfile(callback); } else if (RAWBUTTON_TOGGLE_PLAYER.equals(profileTypeUID)) { return new RawButtonTogglePlayerProfile(callback); } else if (RAWROCKER_DIMMER.equals(profileTypeUID)) { @@ -89,6 +92,10 @@ public class SystemProfileFactory implements ProfileFactory, ProfileAdvisor, Pro return new RawRockerPlayPauseProfile(callback); } else if (RAWROCKER_REWIND_FASTFORWARD.equals(profileTypeUID)) { return new RawRockerRewindFastforwardProfile(callback); + } else if (RAWROCKER_STOP_MOVE.equals(profileTypeUID)) { + return new RawRockerStopMoveProfile(callback); + } else if (RAWROCKER_UP_DOWN.equals(profileTypeUID)) { + return new RawRockerUpDownProfile(callback); } else if (TIMESTAMP_CHANGE.equals(profileTypeUID)) { return new TimestampChangeProfile(callback); } else if (TIMESTAMP_UPDATE.equals(profileTypeUID)) { @@ -111,6 +118,8 @@ public class SystemProfileFactory implements ProfileFactory, ProfileAdvisor, Pro if (DefaultSystemChannelTypeProvider.SYSTEM_RAWBUTTON.getUID().equals(channelType.getUID())) { if (CoreItemFactory.PLAYER.equalsIgnoreCase(itemType)) { return RAWBUTTON_TOGGLE_PLAYER; + } else if (CoreItemFactory.ROLLERSHUTTER.equalsIgnoreCase(itemType)) { + return RAWBUTTON_TOGGLE_ROLLERSHUTTER; } else if (CoreItemFactory.SWITCH.equalsIgnoreCase(itemType)) { return RAWBUTTON_TOGGLE_SWITCH; } @@ -119,6 +128,8 @@ public class SystemProfileFactory implements ProfileFactory, ProfileAdvisor, Pro return RAWROCKER_DIMMER; } else if (CoreItemFactory.PLAYER.equalsIgnoreCase(itemType)) { return RAWROCKER_PLAY_PAUSE; + } else if (CoreItemFactory.ROLLERSHUTTER.equalsIgnoreCase(itemType)) { + return RAWROCKER_UP_DOWN; } else if (CoreItemFactory.SWITCH.equalsIgnoreCase(itemType)) { return RAWROCKER_ON_OFF; } diff --git a/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/profiles/SystemProfiles.java b/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/profiles/SystemProfiles.java index 8a2be37816..2d62ed039a 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/profiles/SystemProfiles.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/eclipse/smarthome/core/thing/profiles/SystemProfiles.java @@ -12,6 +12,8 @@ */ package org.eclipse.smarthome.core.thing.profiles; +import static org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID.SYSTEM_SCOPE; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.smarthome.core.library.CoreItemFactory; import org.eclipse.smarthome.core.thing.DefaultSystemChannelTypeProvider; @@ -24,20 +26,21 @@ import org.eclipse.smarthome.core.thing.DefaultSystemChannelTypeProvider; @NonNullByDefault public interface SystemProfiles { - ProfileTypeUID DEFAULT = new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, "default"); - ProfileTypeUID FOLLOW = new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, "follow"); - ProfileTypeUID OFFSET = new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, "offset"); - ProfileTypeUID RAWBUTTON_TOGGLE_PLAYER = new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, "rawbutton-toggle-player"); - ProfileTypeUID RAWBUTTON_TOGGLE_SWITCH = new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, "rawbutton-toggle-switch"); - ProfileTypeUID RAWROCKER_DIMMER = new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, "rawrocker-to-dimmer"); - ProfileTypeUID RAWROCKER_NEXT_PREVIOUS = new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, - "rawrocker-to-next-previous"); - ProfileTypeUID RAWROCKER_ON_OFF = new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, "rawrocker-to-on-off"); - ProfileTypeUID RAWROCKER_PLAY_PAUSE = new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, "rawrocker-to-play-pause"); - ProfileTypeUID RAWROCKER_REWIND_FASTFORWARD = new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, - "rawrocker-to-rewind-fastforward"); - ProfileTypeUID TIMESTAMP_CHANGE = new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, "timestamp-change"); - ProfileTypeUID TIMESTAMP_UPDATE = new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, "timestamp-update"); + ProfileTypeUID DEFAULT = new ProfileTypeUID(SYSTEM_SCOPE, "default"); + ProfileTypeUID FOLLOW = new ProfileTypeUID(SYSTEM_SCOPE, "follow"); + ProfileTypeUID OFFSET = new ProfileTypeUID(SYSTEM_SCOPE, "offset"); + ProfileTypeUID RAWBUTTON_TOGGLE_PLAYER = new ProfileTypeUID(SYSTEM_SCOPE, "rawbutton-toggle-player"); + ProfileTypeUID RAWBUTTON_TOGGLE_ROLLERSHUTTER = new ProfileTypeUID(SYSTEM_SCOPE, "rawbutton-toggle-rollershutter"); + ProfileTypeUID RAWBUTTON_TOGGLE_SWITCH = new ProfileTypeUID(SYSTEM_SCOPE, "rawbutton-toggle-switch"); + ProfileTypeUID RAWROCKER_DIMMER = new ProfileTypeUID(SYSTEM_SCOPE, "rawrocker-to-dimmer"); + ProfileTypeUID RAWROCKER_NEXT_PREVIOUS = new ProfileTypeUID(SYSTEM_SCOPE, "rawrocker-to-next-previous"); + ProfileTypeUID RAWROCKER_ON_OFF = new ProfileTypeUID(SYSTEM_SCOPE, "rawrocker-to-on-off"); + ProfileTypeUID RAWROCKER_PLAY_PAUSE = new ProfileTypeUID(SYSTEM_SCOPE, "rawrocker-to-play-pause"); + ProfileTypeUID RAWROCKER_REWIND_FASTFORWARD = new ProfileTypeUID(SYSTEM_SCOPE, "rawrocker-to-rewind-fastforward"); + ProfileTypeUID RAWROCKER_STOP_MOVE = new ProfileTypeUID(SYSTEM_SCOPE, "rawrocker-to-stop-move"); + ProfileTypeUID RAWROCKER_UP_DOWN = new ProfileTypeUID(SYSTEM_SCOPE, "rawrocker-to-up-down"); + ProfileTypeUID TIMESTAMP_CHANGE = new ProfileTypeUID(SYSTEM_SCOPE, "timestamp-change"); + ProfileTypeUID TIMESTAMP_UPDATE = new ProfileTypeUID(SYSTEM_SCOPE, "timestamp-update"); StateProfileType DEFAULT_TYPE = ProfileTypeBuilder.newState(DEFAULT, "Default").build(); @@ -52,6 +55,11 @@ public interface SystemProfiles { .withSupportedItemTypes(CoreItemFactory.PLAYER) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_RAWBUTTON.getUID()).build(); + TriggerProfileType RAWBUTTON_TOGGLE_ROLLERSHUTTER_TYPE = ProfileTypeBuilder + .newTrigger(RAWBUTTON_TOGGLE_ROLLERSHUTTER, "Raw Button Toggle Rollershutter") + .withSupportedItemTypes(CoreItemFactory.ROLLERSHUTTER) + .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_RAWBUTTON.getUID()).build(); + TriggerProfileType RAWBUTTON_TOGGLE_SWITCH_TYPE = ProfileTypeBuilder .newTrigger(RAWBUTTON_TOGGLE_SWITCH, "Raw Button Toggle Switch") .withSupportedItemTypes(CoreItemFactory.SWITCH, CoreItemFactory.DIMMER, CoreItemFactory.COLOR) @@ -79,6 +87,16 @@ public interface SystemProfiles { .withSupportedItemTypes(CoreItemFactory.PLAYER) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_RAWROCKER.getUID()).build(); + TriggerProfileType RAWROCKER_STOP_MOVE_TYPE = ProfileTypeBuilder + .newTrigger(RAWROCKER_STOP_MOVE, "Raw Rocker To Stop/Move") + .withSupportedItemTypes(CoreItemFactory.ROLLERSHUTTER) + .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_RAWROCKER.getUID()).build(); + + TriggerProfileType RAWROCKER_UP_DOWN_TYPE = ProfileTypeBuilder + .newTrigger(RAWROCKER_UP_DOWN, "Raw Rocker To Up/Down") + .withSupportedItemTypes(CoreItemFactory.ROLLERSHUTTER) + .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_RAWROCKER.getUID()).build(); + StateProfileType TIMESTAMP_CHANGE_TYPE = ProfileTypeBuilder.newState(TIMESTAMP_CHANGE, "Timestamp on change") .withSupportedItemTypes(CoreItemFactory.DATETIME).build();