Compare commits

...

6 Commits

Author SHA1 Message Date
Christian Weimann
47a862780d style(SceneMgr): reorder import statements for consistency 2025-01-12 12:18:24 +01:00
Christian Weimann
fd10e13238 refactor(scene): extract scenes initialization into a separate method 2025-01-12 07:09:31 +01:00
Christian Weimann
6d7d00fcd3 refactor(scene): rename accumulator variable in scenes reducer 2025-01-12 07:07:33 +01:00
Christian Weimann
2571f9c01e chore(logging): add informational logs for SceneMgr and Scene initialization 2025-01-12 06:58:43 +01:00
Christian Weimann
0c5566a7eb fix(scene): correct method call to createSceneSwitchItem 2025-01-11 10:05:45 +01:00
Christian Weimann
27446b13b8 feat(scene-manager): add 'Scene' tag to stateful scene switch items 2025-01-11 10:00:19 +01:00

View File

@@ -8,18 +8,27 @@ const log = Java.type('org.slf4j.LoggerFactory').getLogger(LOGGER);
// Load dependencies
const { TimerMgr } = require('../utils');
const { ruleRegistry } = require('@runtime/RuleSupport');
const tm = new TimerMgr();
const { ruleRegistry } = require('@runtime/RuleSupport');
// Functions
class SceneMgr {
constructor() {
this.scenes = this.getScenes().reduce((accumulator, scene) => {
// Log the initialization message for Scene Manager.
log.info('Initialization of SceneMgr');
// Initialize the scenes map by reducing the array of scenes into an object with unique IDs as keys.
this.scenes = this.initializeScenes();
}
// Helper method to initialize scenes using reduce.
initializeScenes() {
return this.getScenes().reduce((scenes, scene) => {
const sceneUID = scene.getUID();
accumulator[sceneUID] = new Scene(scene);
return accumulator;
scenes[sceneUID] = new Scene(scene);
return scenes;
}, {});
}
@@ -70,8 +79,10 @@ class Scene {
this.sceneSwitchItemName = ITEMPREFIX + "_" + this.sceneUID;
this.evaluationRuleUID = "SceneItems" + this.sceneUID;
log.info(`Initialize scene ${this.sceneName}`);
if (!items[this.sceneSwitchItemName]) {
createSceneSwitchItem();
this.createSceneSwitchItem();
}
this.createSceneRules();
@@ -83,7 +94,7 @@ class Scene {
name: this.sceneSwitchItemName,
type: 'Switch',
label: `Switch for stateful scene ${this.sceneName}`,
tags: ['Stateful', 'Control']
tags: ['Stateful', 'Control', 'Scene']
});
}
@@ -254,9 +265,9 @@ const sm = new SceneMgr();
// Unload script
require('@runtime').lifecycleTracker.addDisposeHook(() => {
log.info('Deinitialization of SceneMgr.js');
log.info('Deinitialization of SceneMgr');
sm.purgeUnusedSceneSwitchItems();
tm.cancelAll();
});
});