From bff92e0349724c7b61775e780d54c2115eade506 Mon Sep 17 00:00:00 2001 From: jimtng <2554958+jimtng@users.noreply.github.com> Date: Sat, 22 Apr 2023 16:18:49 +1000 Subject: [PATCH] Improve log message to identify profile's link (#3568) --- .../automation/module/script/profile/ScriptProfile.java | 3 ++- .../module/script/profile/ScriptProfileTest.java | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/profile/ScriptProfile.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/profile/ScriptProfile.java index cb2634afc67..e9e720bcb5f 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/profile/ScriptProfile.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/profile/ScriptProfile.java @@ -76,7 +76,8 @@ public ScriptProfile(ProfileTypeUID profileTypeUID, ProfileCallback callback, Pr if (toItemScript.isBlank() && toHandlerScript.isBlank()) { logger.error( - "Neither 'toItem' nor 'toHandler' script defined. Profile will discard all states and commands."); + "Neither 'toItemScript' nor 'toHandlerScript' defined in link '{}'. Profile will discard all states and commands.", + callback.getItemChannelLink()); isConfigured = false; return; } diff --git a/bundles/org.openhab.core.automation.module.script/src/test/java/org/openhab/core/automation/module/script/profile/ScriptProfileTest.java b/bundles/org.openhab.core.automation.module.script/src/test/java/org/openhab/core/automation/module/script/profile/ScriptProfileTest.java index 11111ec4499..d4268e65fe8 100644 --- a/bundles/org.openhab.core.automation.module.script/src/test/java/org/openhab/core/automation/module/script/profile/ScriptProfileTest.java +++ b/bundles/org.openhab.core.automation.module.script/src/test/java/org/openhab/core/automation/module/script/profile/ScriptProfileTest.java @@ -40,6 +40,8 @@ import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.PercentType; import org.openhab.core.test.java.JavaTest; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.link.ItemChannelLink; import org.openhab.core.thing.profiles.ProfileCallback; import org.openhab.core.thing.profiles.ProfileContext; import org.openhab.core.thing.profiles.ProfileTypeUID; @@ -70,6 +72,9 @@ public void setUp() throws TransformationException { public void testScriptNotExecutedAndNoValueForwardedToCallbackIfNoScriptDefined() throws TransformationException { ProfileContext profileContext = ProfileContextBuilder.create().build(); + ItemChannelLink link = new ItemChannelLink("DummyItem", new ChannelUID("foo:bar:baz:qux")); + when(profileCallback.getItemChannelLink()).thenReturn(link); + setupInterceptedLogger(ScriptProfile.class, LogLevel.ERROR); ScriptProfile scriptProfile = new ScriptProfile(mock(ProfileTypeUID.class), profileCallback, profileContext, @@ -85,7 +90,8 @@ public void testScriptNotExecutedAndNoValueForwardedToCallbackIfNoScriptDefined( verify(profileCallback, never()).sendCommand(any()); assertLogMessage(ScriptProfile.class, LogLevel.ERROR, - "Neither 'toItem' nor 'toHandler' script defined. Profile will discard all states and commands."); + "Neither 'toItemScript' nor 'toHandlerScript' defined in link '" + link.toString() + + "'. Profile will discard all states and commands."); } @Test