From 192e4a2347a670f5adec957a3ac3f68f6bf48a89 Mon Sep 17 00:00:00 2001 From: J-N-K Date: Wed, 23 Feb 2022 21:17:11 +0100 Subject: [PATCH] Add a profile for linking trigger channels to String items (#2769) * Add a profile for linking trigger channels to String items Signed-off-by: Jan N. Klug --- .../profiles/SystemProfileFactory.java | 13 ++- .../profiles/TriggerEventStringProfile.java | 51 ++++++++ .../core/thing/profiles/SystemProfiles.java | 109 ++++++++---------- .../TriggerEventStringProfileTest.java | 46 ++++++++ .../SystemProfileFactoryOSGiTest.java | 2 +- 5 files changed, 158 insertions(+), 63 deletions(-) create mode 100644 bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/TriggerEventStringProfile.java create mode 100644 bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/TriggerEventStringProfileTest.java diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactory.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactory.java index eed09b8b332..79b44a431e4 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactory.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactory.java @@ -66,14 +66,15 @@ public class SystemProfileFactory implements ProfileFactory, ProfileAdvisor, Pro OFFSET_TYPE, RANGE_TYPE, RAWBUTTON_ON_OFF_SWITCH_TYPE, RAWBUTTON_TOGGLE_PLAYER_TYPE, RAWBUTTON_TOGGLE_ROLLERSHUTTER_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_OFFSET_TYPE, TIMESTAMP_TRIGGER_TYPE, TIMESTAMP_UPDATE_TYPE); + RAWROCKER_REWIND_FASTFORWARD_TYPE, RAWROCKER_STOP_MOVE_TYPE, RAWROCKER_UP_DOWN_TYPE, + TRIGGER_EVENT_STRING_TYPE, TIMESTAMP_CHANGE_TYPE, TIMESTAMP_OFFSET_TYPE, TIMESTAMP_TRIGGER_TYPE, + TIMESTAMP_UPDATE_TYPE); private static final Set SUPPORTED_PROFILE_TYPE_UIDS = Set.of(DEFAULT, FOLLOW, HYSTERESIS, OFFSET, RANGE, RAWBUTTON_ON_OFF_SWITCH, RAWBUTTON_TOGGLE_PLAYER, RAWBUTTON_TOGGLE_ROLLERSHUTTER, 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_OFFSET, - TIMESTAMP_TRIGGER, TIMESTAMP_UPDATE); + RAWROCKER_REWIND_FASTFORWARD, RAWROCKER_STOP_MOVE, RAWROCKER_UP_DOWN, TRIGGER_EVENT_STRING, + TIMESTAMP_CHANGE, TIMESTAMP_OFFSET, TIMESTAMP_TRIGGER, TIMESTAMP_UPDATE); private final Map localizedProfileTypeCache = new ConcurrentHashMap<>(); @@ -124,6 +125,8 @@ public SystemProfileFactory(final @Reference ChannelTypeRegistry channelTypeRegi return new RawRockerStopMoveProfile(callback); } else if (RAWROCKER_UP_DOWN.equals(profileTypeUID)) { return new RawRockerUpDownProfile(callback); + } else if (TRIGGER_EVENT_STRING.equals(profileTypeUID)) { + return new TriggerEventStringProfile(callback); } else if (TIMESTAMP_CHANGE.equals(profileTypeUID)) { return new TimestampChangeProfile(callback); } else if (TIMESTAMP_OFFSET.equals(profileTypeUID)) { @@ -165,6 +168,8 @@ public SystemProfileFactory(final @Reference ChannelTypeRegistry channelTypeRegi } else if (CoreItemFactory.SWITCH.equalsIgnoreCase(itemType)) { return RAWROCKER_ON_OFF; } + } else if (CoreItemFactory.STRING.equalsIgnoreCase(itemType)) { + return TRIGGER_EVENT_STRING; } break; default: diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/TriggerEventStringProfile.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/TriggerEventStringProfile.java new file mode 100644 index 00000000000..d4dc58b17ba --- /dev/null +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/TriggerEventStringProfile.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2010-2022 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.openhab.core.thing.internal.profiles; + +import static org.openhab.core.thing.profiles.SystemProfiles.TRIGGER_EVENT_STRING; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.core.library.types.StringType; +import org.openhab.core.thing.profiles.ProfileCallback; +import org.openhab.core.thing.profiles.ProfileTypeUID; +import org.openhab.core.thing.profiles.TriggerProfile; +import org.openhab.core.types.State; + +/** + * The {@link TriggerEventStringProfile} transforms a trigger event to a String + * + * @author Jan N. Klug - Initial contribution + */ +@NonNullByDefault +public class TriggerEventStringProfile implements TriggerProfile { + + private final ProfileCallback callback; + + TriggerEventStringProfile(ProfileCallback callback) { + this.callback = callback; + } + + @Override + public ProfileTypeUID getProfileTypeUID() { + return TRIGGER_EVENT_STRING; + } + + @Override + public void onStateUpdateFromItem(State state) { + } + + @Override + public void onTriggerFromHandler(String event) { + callback.sendCommand(new StringType(event)); + } +} diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/profiles/SystemProfiles.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/profiles/SystemProfiles.java index 98a7fa88b38..d481015185f 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/profiles/SystemProfiles.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/profiles/SystemProfiles.java @@ -26,116 +26,109 @@ @NonNullByDefault public interface SystemProfiles { - public static final ProfileTypeUID DEFAULT = new ProfileTypeUID(SYSTEM_SCOPE, "default"); - public static final ProfileTypeUID FOLLOW = new ProfileTypeUID(SYSTEM_SCOPE, "follow"); - public static final ProfileTypeUID OFFSET = new ProfileTypeUID(SYSTEM_SCOPE, "offset"); - public static final ProfileTypeUID HYSTERESIS = new ProfileTypeUID(SYSTEM_SCOPE, "hysteresis"); - public static final ProfileTypeUID RANGE = new ProfileTypeUID(SYSTEM_SCOPE, "range"); - public static final ProfileTypeUID RAWBUTTON_ON_OFF_SWITCH = new ProfileTypeUID(SYSTEM_SCOPE, - "rawbutton-on-off-switch"); - public static final ProfileTypeUID RAWBUTTON_TOGGLE_PLAYER = new ProfileTypeUID(SYSTEM_SCOPE, - "rawbutton-toggle-player"); - public static final ProfileTypeUID RAWBUTTON_TOGGLE_ROLLERSHUTTER = new ProfileTypeUID(SYSTEM_SCOPE, - "rawbutton-toggle-rollershutter"); - public static final ProfileTypeUID RAWBUTTON_TOGGLE_SWITCH = new ProfileTypeUID(SYSTEM_SCOPE, - "rawbutton-toggle-switch"); - public static final ProfileTypeUID RAWROCKER_DIMMER = new ProfileTypeUID(SYSTEM_SCOPE, "rawrocker-to-dimmer"); - public static final ProfileTypeUID RAWROCKER_NEXT_PREVIOUS = new ProfileTypeUID(SYSTEM_SCOPE, - "rawrocker-to-next-previous"); - public static final ProfileTypeUID RAWROCKER_ON_OFF = new ProfileTypeUID(SYSTEM_SCOPE, "rawrocker-to-on-off"); - public static final ProfileTypeUID RAWROCKER_PLAY_PAUSE = new ProfileTypeUID(SYSTEM_SCOPE, - "rawrocker-to-play-pause"); - public static final ProfileTypeUID RAWROCKER_REWIND_FASTFORWARD = new ProfileTypeUID(SYSTEM_SCOPE, - "rawrocker-to-rewind-fastforward"); - public static final ProfileTypeUID RAWROCKER_STOP_MOVE = new ProfileTypeUID(SYSTEM_SCOPE, "rawrocker-to-stop-move"); - public static final ProfileTypeUID RAWROCKER_UP_DOWN = new ProfileTypeUID(SYSTEM_SCOPE, "rawrocker-to-up-down"); - public static final ProfileTypeUID TIMESTAMP_CHANGE = new ProfileTypeUID(SYSTEM_SCOPE, "timestamp-change"); - public static final ProfileTypeUID TIMESTAMP_OFFSET = new ProfileTypeUID(SYSTEM_SCOPE, "timestamp-offset"); - public static final ProfileTypeUID TIMESTAMP_TRIGGER = new ProfileTypeUID(SYSTEM_SCOPE, "timestamp-trigger"); - public static final ProfileTypeUID TIMESTAMP_UPDATE = new ProfileTypeUID(SYSTEM_SCOPE, "timestamp-update"); - - static final ProfileType DEFAULT_TYPE = ProfileTypeBuilder.newState(DEFAULT, "Default").build(); - - static final ProfileType FOLLOW_TYPE = ProfileTypeBuilder.newState(FOLLOW, "Follow").build(); - - static final ProfileType OFFSET_TYPE = ProfileTypeBuilder.newState(OFFSET, "Offset") + ProfileTypeUID DEFAULT = new ProfileTypeUID(SYSTEM_SCOPE, "default"); + ProfileTypeUID FOLLOW = new ProfileTypeUID(SYSTEM_SCOPE, "follow"); + ProfileTypeUID OFFSET = new ProfileTypeUID(SYSTEM_SCOPE, "offset"); + ProfileTypeUID HYSTERESIS = new ProfileTypeUID(SYSTEM_SCOPE, "hysteresis"); + ProfileTypeUID RANGE = new ProfileTypeUID(SYSTEM_SCOPE, "range"); + ProfileTypeUID RAWBUTTON_ON_OFF_SWITCH = new ProfileTypeUID(SYSTEM_SCOPE, "rawbutton-on-off-switch"); + 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 TRIGGER_EVENT_STRING = new ProfileTypeUID(SYSTEM_SCOPE, "trigger-event-string"); + ProfileTypeUID TIMESTAMP_CHANGE = new ProfileTypeUID(SYSTEM_SCOPE, "timestamp-change"); + ProfileTypeUID TIMESTAMP_OFFSET = new ProfileTypeUID(SYSTEM_SCOPE, "timestamp-offset"); + ProfileTypeUID TIMESTAMP_TRIGGER = new ProfileTypeUID(SYSTEM_SCOPE, "timestamp-trigger"); + ProfileTypeUID TIMESTAMP_UPDATE = new ProfileTypeUID(SYSTEM_SCOPE, "timestamp-update"); + + ProfileType DEFAULT_TYPE = ProfileTypeBuilder.newState(DEFAULT, "Default").build(); + + ProfileType FOLLOW_TYPE = ProfileTypeBuilder.newState(FOLLOW, "Follow").build(); + + ProfileType OFFSET_TYPE = ProfileTypeBuilder.newState(OFFSET, "Offset") .withSupportedItemTypes(CoreItemFactory.NUMBER).withSupportedItemTypesOfChannel(CoreItemFactory.NUMBER) .build(); - static final ProfileType HYSTERESIS_TYPE = ProfileTypeBuilder.newState(HYSTERESIS, "Hysteresis") // + ProfileType HYSTERESIS_TYPE = ProfileTypeBuilder.newState(HYSTERESIS, "Hysteresis") // .withSupportedItemTypesOfChannel(CoreItemFactory.DIMMER, CoreItemFactory.NUMBER) // .withSupportedItemTypes(CoreItemFactory.SWITCH) // .build(); - static final ProfileType RANGE_TYPE = ProfileTypeBuilder.newState(RANGE, "Range") // + ProfileType RANGE_TYPE = ProfileTypeBuilder.newState(RANGE, "Range") // .withSupportedItemTypesOfChannel(CoreItemFactory.DIMMER, CoreItemFactory.NUMBER) // .withSupportedItemTypes(CoreItemFactory.SWITCH) // .build(); - static final ProfileType RAWBUTTON_ON_OFF_SWITCH_TYPE = ProfileTypeBuilder + ProfileType RAWBUTTON_ON_OFF_SWITCH_TYPE = ProfileTypeBuilder .newTrigger(RAWBUTTON_ON_OFF_SWITCH, "Raw Button To On Off") .withSupportedItemTypes(CoreItemFactory.SWITCH, CoreItemFactory.DIMMER, CoreItemFactory.COLOR) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_RAWBUTTON).build(); - static final ProfileType RAWBUTTON_TOGGLE_PLAYER_TYPE = ProfileTypeBuilder + ProfileType RAWBUTTON_TOGGLE_PLAYER_TYPE = ProfileTypeBuilder .newTrigger(RAWBUTTON_TOGGLE_PLAYER, "Raw Button Toggle Player") .withSupportedItemTypes(CoreItemFactory.PLAYER) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_RAWBUTTON).build(); - static final ProfileType RAWBUTTON_TOGGLE_ROLLERSHUTTER_TYPE = ProfileTypeBuilder + ProfileType RAWBUTTON_TOGGLE_ROLLERSHUTTER_TYPE = ProfileTypeBuilder .newTrigger(RAWBUTTON_TOGGLE_ROLLERSHUTTER, "Raw Button Toggle Rollershutter") .withSupportedItemTypes(CoreItemFactory.ROLLERSHUTTER) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_RAWBUTTON).build(); - static final ProfileType RAWBUTTON_TOGGLE_SWITCH_TYPE = ProfileTypeBuilder + ProfileType RAWBUTTON_TOGGLE_SWITCH_TYPE = ProfileTypeBuilder .newTrigger(RAWBUTTON_TOGGLE_SWITCH, "Raw Button Toggle Switch") .withSupportedItemTypes(CoreItemFactory.SWITCH, CoreItemFactory.DIMMER, CoreItemFactory.COLOR) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_RAWBUTTON).build(); - static final ProfileType RAWROCKER_ON_OFF_TYPE = ProfileTypeBuilder - .newTrigger(RAWROCKER_ON_OFF, "Raw Rocker To On Off") + ProfileType RAWROCKER_ON_OFF_TYPE = ProfileTypeBuilder.newTrigger(RAWROCKER_ON_OFF, "Raw Rocker To On Off") .withSupportedItemTypes(CoreItemFactory.SWITCH, CoreItemFactory.DIMMER, CoreItemFactory.COLOR) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_RAWROCKER).build(); - static final ProfileType RAWROCKER_DIMMER_TYPE = ProfileTypeBuilder - .newTrigger(RAWROCKER_DIMMER, "Raw Rocker To Dimmer").withSupportedItemTypes(CoreItemFactory.DIMMER) + ProfileType RAWROCKER_DIMMER_TYPE = ProfileTypeBuilder.newTrigger(RAWROCKER_DIMMER, "Raw Rocker To Dimmer") + .withSupportedItemTypes(CoreItemFactory.DIMMER) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_RAWROCKER).build(); - static final ProfileType RAWROCKER_NEXT_PREVIOUS_TYPE = ProfileTypeBuilder + ProfileType RAWROCKER_NEXT_PREVIOUS_TYPE = ProfileTypeBuilder .newTrigger(RAWROCKER_NEXT_PREVIOUS, "Raw Rocker To Next/Previous") .withSupportedItemTypes(CoreItemFactory.PLAYER) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_RAWROCKER).build(); - static final ProfileType RAWROCKER_PLAY_PAUSE_TYPE = ProfileTypeBuilder + ProfileType RAWROCKER_PLAY_PAUSE_TYPE = ProfileTypeBuilder .newTrigger(RAWROCKER_PLAY_PAUSE, "Raw Rocker To Play/Pause").withSupportedItemTypes(CoreItemFactory.PLAYER) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_RAWROCKER).build(); - static final ProfileType RAWROCKER_REWIND_FASTFORWARD_TYPE = ProfileTypeBuilder + ProfileType RAWROCKER_REWIND_FASTFORWARD_TYPE = ProfileTypeBuilder .newTrigger(RAWROCKER_REWIND_FASTFORWARD, "Raw Rocker To Rewind/Fastforward") .withSupportedItemTypes(CoreItemFactory.PLAYER) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_RAWROCKER).build(); - static final ProfileType RAWROCKER_STOP_MOVE_TYPE = ProfileTypeBuilder - .newTrigger(RAWROCKER_STOP_MOVE, "Raw Rocker To Stop/Move") + ProfileType RAWROCKER_STOP_MOVE_TYPE = ProfileTypeBuilder.newTrigger(RAWROCKER_STOP_MOVE, "Raw Rocker To Stop/Move") .withSupportedItemTypes(CoreItemFactory.ROLLERSHUTTER) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_RAWROCKER).build(); - static final ProfileType RAWROCKER_UP_DOWN_TYPE = ProfileTypeBuilder - .newTrigger(RAWROCKER_UP_DOWN, "Raw Rocker To Up/Down") + ProfileType RAWROCKER_UP_DOWN_TYPE = ProfileTypeBuilder.newTrigger(RAWROCKER_UP_DOWN, "Raw Rocker To Up/Down") .withSupportedItemTypes(CoreItemFactory.ROLLERSHUTTER) .withSupportedChannelTypeUIDs(DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_TYPE_UID_RAWROCKER).build(); - static final ProfileType TIMESTAMP_CHANGE_TYPE = ProfileTypeBuilder - .newState(TIMESTAMP_CHANGE, "Timestamp on change").withSupportedItemTypes(CoreItemFactory.DATETIME).build(); + ProfileType TRIGGER_EVENT_STRING_TYPE = ProfileTypeBuilder.newTrigger(TRIGGER_EVENT_STRING, "Trigger Event String") + .withSupportedItemTypes(CoreItemFactory.STRING).build(); - static final ProfileType TIMESTAMP_OFFSET_TYPE = ProfileTypeBuilder.newState(TIMESTAMP_OFFSET, "Timestamp Offset") + ProfileType TIMESTAMP_CHANGE_TYPE = ProfileTypeBuilder.newState(TIMESTAMP_CHANGE, "Timestamp on change") + .withSupportedItemTypes(CoreItemFactory.DATETIME).build(); + + ProfileType TIMESTAMP_OFFSET_TYPE = ProfileTypeBuilder.newState(TIMESTAMP_OFFSET, "Timestamp Offset") .withSupportedItemTypes(CoreItemFactory.DATETIME).withSupportedItemTypesOfChannel(CoreItemFactory.DATETIME) .build(); - static final ProfileType TIMESTAMP_TRIGGER_TYPE = ProfileTypeBuilder - .newTrigger(TIMESTAMP_TRIGGER, "Timestamp on Trigger").withSupportedItemTypes(CoreItemFactory.DATETIME) - .build(); + ProfileType TIMESTAMP_TRIGGER_TYPE = ProfileTypeBuilder.newTrigger(TIMESTAMP_TRIGGER, "Timestamp on Trigger") + .withSupportedItemTypes(CoreItemFactory.DATETIME).build(); - static final ProfileType TIMESTAMP_UPDATE_TYPE = ProfileTypeBuilder - .newState(TIMESTAMP_UPDATE, "Timestamp on update").withSupportedItemTypes(CoreItemFactory.DATETIME).build(); + ProfileType TIMESTAMP_UPDATE_TYPE = ProfileTypeBuilder.newState(TIMESTAMP_UPDATE, "Timestamp on update") + .withSupportedItemTypes(CoreItemFactory.DATETIME).build(); } diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/TriggerEventStringProfileTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/TriggerEventStringProfileTest.java new file mode 100644 index 00000000000..c1b6ba489a0 --- /dev/null +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/internal/profiles/TriggerEventStringProfileTest.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2010-2022 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.openhab.core.thing.internal.profiles; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.openhab.core.library.types.StringType; +import org.openhab.core.thing.CommonTriggerEvents; +import org.openhab.core.thing.profiles.ProfileCallback; +import org.openhab.core.thing.profiles.TriggerProfile; + +/** + * Tests for the system:trigger-event-string profile + * + * @author Jan N. Klug - Initial contribution + */ +@ExtendWith(MockitoExtension.class) +@NonNullByDefault +public class TriggerEventStringProfileTest { + + private @Mock @NonNullByDefault({}) ProfileCallback callbackMock; + + @Test + public void testEventStringItem() { + TriggerProfile profile = new TriggerEventStringProfile((callbackMock)); + profile.onTriggerFromHandler(CommonTriggerEvents.PRESSED); + verify(callbackMock, times(1)).sendCommand(eq(new StringType(CommonTriggerEvents.PRESSED))); + } +} diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactoryOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactoryOSGiTest.java index a47c191731a..a9b7534fdda 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactoryOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactoryOSGiTest.java @@ -73,7 +73,7 @@ public void beforeEach() { @Test public void systemProfileTypesAndUidsShouldBeAvailable() { Collection systemProfileTypeUIDs = profileFactory.getSupportedProfileTypeUIDs(); - assertThat(systemProfileTypeUIDs, hasSize(20)); + assertThat(systemProfileTypeUIDs, hasSize(21)); Collection systemProfileTypes = profileFactory.getProfileTypes(null); assertThat(systemProfileTypes, hasSize(systemProfileTypeUIDs.size()));