Skip to content

Commit 508f1f6

Browse files
authored
ScriptTransformationService: Implement missing script dependency tracking (#5062)
Closes #5046. Signed-off-by: Florian Hotze <[email protected]>
1 parent 5972b1e commit 508f1f6

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@
6464
* language
6565
*
6666
* @author Jan N. Klug - Initial contribution
67+
* @author Florian Hotze - Implement script dependency tracking
6768
*/
6869
@NonNullByDefault
6970
@Component(factory = "org.openhab.core.automation.module.script.transformation.factory", service = {
70-
TransformationService.class, ScriptTransformationService.class, ConfigOptionProvider.class,
71-
ConfigDescriptionProvider.class })
72-
public class ScriptTransformationService implements TransformationService, ConfigOptionProvider,
73-
ConfigDescriptionProvider, RegistryChangeListener<Transformation> {
71+
TransformationService.class, ScriptTransformationService.class, ScriptDependencyTracker.Listener.class,
72+
ConfigOptionProvider.class, ConfigDescriptionProvider.class })
73+
public class ScriptTransformationService implements TransformationService, ScriptDependencyTracker.Listener,
74+
ConfigOptionProvider, ConfigDescriptionProvider, RegistryChangeListener<Transformation> {
7475
public static final String SCRIPT_TYPE_PROPERTY_NAME = "openhab.transform.script.scriptType";
7576
public static final String OPENHAB_TRANSFORMATION_SCRIPT = "openhab-transformation-script-";
7677

@@ -298,6 +299,16 @@ public Collection<ConfigDescription> getConfigDescriptions(@Nullable Locale loca
298299
.withParameterGroups(template.getParameterGroups()).build();
299300
}
300301

302+
@Override
303+
public void onDependencyChange(String scriptId) {
304+
String scriptUid = scriptId.substring(OPENHAB_TRANSFORMATION_SCRIPT.length());
305+
ScriptRecord scriptRecord = scriptCache.get(scriptUid);
306+
if (scriptRecord != null) {
307+
logger.debug("Clearing script cache for script {}", scriptUid);
308+
clearCache(scriptUid);
309+
}
310+
}
311+
301312
private void clearCache(String uid) {
302313
ScriptRecord scriptRecord = scriptCache.remove(uid);
303314
if (scriptRecord != null) {

0 commit comments

Comments
 (0)