-
-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <github@klug.nrw>
- Loading branch information
Showing
5 changed files
with
158 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ing/src/main/java/org/openhab/core/thing/internal/profiles/TriggerEventStringProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...src/test/java/org/openhab/core/thing/internal/profiles/TriggerEventStringProfileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters