Skip to content

Commit 3497353

Browse files
committed
[actions] Fix missing timer identifier for UI scripts
Caused by openhab/openhab-core#4289. Signed-off-by: Florian Hotze <[email protected]>
1 parent a9ca3e7 commit 3497353

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/actions/actions.js

+1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class ScriptExecution {
266266
* @returns {*} a native openHAB Timer
267267
*/
268268
static createTimer (identifier, zdt, functionRef, ...params) {
269+
ThreadsafeTimers.setIdentifier(console.loggerName); // eslint-disable-line no-undef
269270
// Support method overloading as identifier is optional
270271
if (typeof identifier === 'string' && functionRef != null) {
271272
const callbackFn = () => functionRef(...params);

test/actions.spec.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ jest.mock('../src/osgi');
77

88
describe('actions.js', () => {
99
describe('ScriptExecution', () => {
10+
const defaultIdentifier = 'script-1';
11+
1012
beforeAll(() => {
1113
jest.spyOn(JavaScriptExecution, 'callScript');
1214
jest.spyOn(JavaScriptExecution, 'createTimer');
1315

16+
console.loggerName = defaultIdentifier;
1417
ThreadsafeTimers = {
18+
setIdentifier: jest.fn(),
1519
createTimer: jest.fn()
1620
};
1721
});
@@ -31,16 +35,29 @@ describe('actions.js', () => {
3135

3236
ScriptExecution.createTimer(identifier, zdt, functionRef, 'prop1');
3337

38+
expect(ThreadsafeTimers.setIdentifier).toHaveBeenCalledWith(defaultIdentifier);
3439
expect(ThreadsafeTimers.createTimer).toHaveBeenCalled();
3540
expect(JavaScriptExecution.callScript).not.toHaveBeenCalled();
3641

37-
jest.clearAllMocks();
38-
3942
ScriptExecution.createTimer(zdt, functionRef, 'prop1');
4043

44+
expect(ThreadsafeTimers.setIdentifier).toHaveBeenCalledWith(defaultIdentifier);
4145
expect(ThreadsafeTimers.createTimer).toHaveBeenCalled();
4246
expect(JavaScriptExecution.callScript).not.toHaveBeenCalled();
4347
});
48+
49+
it('sets default identifier for ThreadsafeTimers.', () => {
50+
const zdt = {};
51+
const functionRef = (foo) => foo;
52+
53+
ScriptExecution.createTimer(zdt, functionRef, 'prop1');
54+
55+
expect(ThreadsafeTimers.setIdentifier).toHaveBeenCalledWith(defaultIdentifier);
56+
57+
ScriptExecution.createTimer(zdt, functionRef, 'prop1');
58+
59+
expect(ThreadsafeTimers.setIdentifier).toHaveBeenCalledWith(defaultIdentifier);
60+
});
4461
});
4562

4663
describe('Transformation', () => {

types/actions/actions.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

0 commit comments

Comments
 (0)