Compare commits
6 Commits
47d6b80511
...
47a862780d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47a862780d | ||
|
|
fd10e13238 | ||
|
|
6d7d00fcd3 | ||
|
|
2571f9c01e | ||
|
|
0c5566a7eb | ||
|
|
27446b13b8 |
29
SceneMgr.js
29
SceneMgr.js
@@ -8,18 +8,27 @@ const log = Java.type('org.slf4j.LoggerFactory').getLogger(LOGGER);
|
|||||||
|
|
||||||
// Load dependencies
|
// Load dependencies
|
||||||
const { TimerMgr } = require('../utils');
|
const { TimerMgr } = require('../utils');
|
||||||
const { ruleRegistry } = require('@runtime/RuleSupport');
|
|
||||||
|
|
||||||
const tm = new TimerMgr();
|
const tm = new TimerMgr();
|
||||||
|
|
||||||
|
const { ruleRegistry } = require('@runtime/RuleSupport');
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
class SceneMgr {
|
class SceneMgr {
|
||||||
|
|
||||||
constructor() {
|
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();
|
const sceneUID = scene.getUID();
|
||||||
accumulator[sceneUID] = new Scene(scene);
|
scenes[sceneUID] = new Scene(scene);
|
||||||
return accumulator;
|
return scenes;
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +79,10 @@ class Scene {
|
|||||||
this.sceneSwitchItemName = ITEMPREFIX + "_" + this.sceneUID;
|
this.sceneSwitchItemName = ITEMPREFIX + "_" + this.sceneUID;
|
||||||
this.evaluationRuleUID = "SceneItems" + this.sceneUID;
|
this.evaluationRuleUID = "SceneItems" + this.sceneUID;
|
||||||
|
|
||||||
|
log.info(`Initialize scene ${this.sceneName}`);
|
||||||
|
|
||||||
if (!items[this.sceneSwitchItemName]) {
|
if (!items[this.sceneSwitchItemName]) {
|
||||||
createSceneSwitchItem();
|
this.createSceneSwitchItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.createSceneRules();
|
this.createSceneRules();
|
||||||
@@ -83,7 +94,7 @@ class Scene {
|
|||||||
name: this.sceneSwitchItemName,
|
name: this.sceneSwitchItemName,
|
||||||
type: 'Switch',
|
type: 'Switch',
|
||||||
label: `Switch for stateful scene ${this.sceneName}`,
|
label: `Switch for stateful scene ${this.sceneName}`,
|
||||||
tags: ['Stateful', 'Control']
|
tags: ['Stateful', 'Control', 'Scene']
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,9 +265,9 @@ const sm = new SceneMgr();
|
|||||||
|
|
||||||
// Unload script
|
// Unload script
|
||||||
require('@runtime').lifecycleTracker.addDisposeHook(() => {
|
require('@runtime').lifecycleTracker.addDisposeHook(() => {
|
||||||
log.info('Deinitialization of SceneMgr.js');
|
log.info('Deinitialization of SceneMgr');
|
||||||
|
|
||||||
sm.purgeUnusedSceneSwitchItems();
|
sm.purgeUnusedSceneSwitchItems();
|
||||||
|
|
||||||
tm.cancelAll();
|
tm.cancelAll();
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user