Compare commits

...

3 Commits

Author SHA1 Message Date
Christian Weimann
13bbf41d0b refactor(SceneController): rename SceneMgr to SceneController 2025-01-14 03:54:21 +01:00
Christian Weimann
de8e708088 refactor(SceneMgr): inline scene initialization method 2025-01-14 03:50:51 +01:00
Christian Weimann
fa635f46d9 fix(TimerMgr): cancel existing timer before creating a new one 2025-01-13 08:59:18 +01:00
2 changed files with 8 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
// Settings
const ITEMPREFIX = "System_StatefulScene";
const DEBOUNCETIME = 3000;
const LOGGER = "org.openhab.js.SceneMgr";
const LOGGER = "org.openhab.js.SceneController";
// Logging
const log = Java.type('org.slf4j.LoggerFactory').getLogger(LOGGER);
@@ -13,19 +13,14 @@ const tm = new TimerMgr();
const { ruleRegistry } = require('@runtime/RuleSupport');
// Functions
class SceneMgr {
class SceneController {
constructor() {
// Log the initialization message for Scene Manager.
log.info('Initialization of SceneMgr');
// Log the initialization message for SceneController.
log.info('Initialization of SceneController');
// 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) => {
this.scenes = this.getScenes().reduce((scenes, scene) => {
const sceneUID = scene.getUID();
scenes[sceneUID] = new Scene(scene);
return scenes;
@@ -264,11 +259,11 @@ class Scene {
}
// Load script
const sm = new SceneMgr();
const sm = new SceneController();
// Unload script
require('@runtime').lifecycleTracker.addDisposeHook(() => {
log.info('Deinitialization of SceneMgr');
log.info('Deinitialization of SceneController');
sm.purgeUnusedSceneSwitchItems();

View File

@@ -11,8 +11,7 @@ class TimerMgr {
create(id, timeout, func, ...params) {
if (this.hasTimer(id)) {
log.error(`Timer with id ${id} already exists`);
return;
this.cancel(id);
}
log.debug("Create timer with id " + id);
this.#timers[id] = actions.ScriptExecution.createTimer(id, timeout, func, ...params);