Script profile: Fix deprecation warning (#4110)

Refs #4058.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This commit is contained in:
Florian Hotze 2024-03-02 10:46:28 +01:00 committed by GitHub
parent 45f8bff876
commit d26aa080ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 2 deletions

View File

@ -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()) {

View File

@ -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")