mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 11:45:49 +01:00
Script profile: Fix deprecation warning (#4110)
Refs #4058. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This commit is contained in:
parent
45f8bff876
commit
d26aa080ab
@ -83,8 +83,10 @@ public class ScriptProfile implements StateProfile {
|
||||
this.stateFromItemScript = ConfigParser
|
||||
.valueAsOrElse(profileContext.getConfiguration().get(CONFIG_STATE_FROM_ITEM_SCRIPT), String.class, "");
|
||||
|
||||
if (!toHandlerScript.isBlank() && commandFromItemScript.isBlank()) {
|
||||
logger.warn("'toHandlerScript' has been deprecated! Please use 'commandFromItemScript' instead.");
|
||||
if (!toHandlerScript.isBlank() && localCommandFromItemScript.isBlank()) {
|
||||
logger.warn(
|
||||
"'toHandlerScript' has been deprecated! Please use 'commandFromItemScript' instead in link '{}'.",
|
||||
callback.getItemChannelLink());
|
||||
}
|
||||
|
||||
if (toItemScript.isBlank() && commandFromItemScript.isBlank() && stateFromItemScript.isBlank()) {
|
||||
|
@ -96,6 +96,37 @@ public class ScriptProfileTest extends JavaTest {
|
||||
+ link.toString() + "'. Profile will discard all states and commands.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fallsBackToToHandlerScriptIfCommandFromItemScriptNotDefined() throws TransformationException {
|
||||
ProfileContext profileContext = ProfileContextBuilder.create().withToItemScript("inScript")
|
||||
.withToHandlerScript("outScript").withAcceptedCommandTypes(List.of(OnOffType.class))
|
||||
.withAcceptedDataTypes(List.of(OnOffType.class))
|
||||
.withHandlerAcceptedCommandTypes(List.of(OnOffType.class)).build();
|
||||
|
||||
ItemChannelLink link = new ItemChannelLink("DummyItem", new ChannelUID("foo:bar:baz:qux"));
|
||||
when(profileCallback.getItemChannelLink()).thenReturn(link);
|
||||
|
||||
when(transformationServiceMock.transform(any(), any())).thenReturn(OnOffType.OFF.toString());
|
||||
|
||||
setupInterceptedLogger(ScriptProfile.class, LogLevel.WARN);
|
||||
|
||||
ScriptProfile scriptProfile = new ScriptProfile(mock(ProfileTypeUID.class), profileCallback, profileContext,
|
||||
transformationServiceMock);
|
||||
|
||||
scriptProfile.onCommandFromHandler(DecimalType.ZERO);
|
||||
scriptProfile.onStateUpdateFromHandler(DecimalType.ZERO);
|
||||
scriptProfile.onCommandFromItem(DecimalType.ZERO);
|
||||
|
||||
verify(transformationServiceMock, times(3)).transform(any(), any());
|
||||
verify(profileCallback, times(1)).handleCommand(OnOffType.OFF);
|
||||
verify(profileCallback).sendUpdate(OnOffType.OFF);
|
||||
verify(profileCallback).sendCommand(OnOffType.OFF);
|
||||
|
||||
assertLogMessage(ScriptProfile.class, LogLevel.WARN,
|
||||
"'toHandlerScript' has been deprecated! Please use 'commandFromItemScript' instead in link '"
|
||||
+ link.toString() + "'.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptExecutionErrorForwardsNoValueToCallback() throws TransformationException {
|
||||
ProfileContext profileContext = ProfileContextBuilder.create().withToItemScript("inScript")
|
||||
|
Loading…
Reference in New Issue
Block a user