Regex for ID in subscribe does not work
Hi,
i'd like to use a Regex in my javascript on subscribe part
i have the following code:
on({ id: /^hm-rpc.\d..+.SET_TEMPERATURE$/, },
This gives me the following javascript error in the logs.
| javascript.0 | 2020-03-27 07:12:53.074 | error | (20461) at ContextifyScript.Script.runInContext (vm.js:59:29) |
|---|---|---|---|
| javascript.0 | 2020-03-27 07:12:53.074 | error | (20461) at script.js.common.notifiy-onTempChange:1:1 |
| javascript.0 | 2020-03-27 07:12:53.072 | error | (20461) at on (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1200:28) |
| javascript.0 | 2020-03-27 07:12:53.071 | error | (20461) at Object.subscribe (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1130:13) |
| javascript.0 | 2020-03-27 07:12:53.069 | error | (20461) at subscribePattern (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:101:29) |
| javascript.0 | 2020-03-27 07:12:53.068 | error | (20461) at Adapter.getForeignStates (/opt/iobroker/node_modules/iobroker.js-controller/lib/adapter.js:5920:43) |
| javascript.0 | 2020-03-27 07:12:53.067 | error | (20461) TypeError: pattern.replace is not a function |
| javascript.0 | 2020-03-27 07:12:53.065 | error | (20461) ^ |
| javascript.0 | 2020-03-27 07:12:53.064 | error | (20461) startkey: pattern.replace(/*/g, ''), |
| javascript.0 | 2020-03-27 07:12:53.063 | error | (20461) script.js.common.notifiy-onTempChange: /opt/iobroker/node_modules/iobroker.js-controller/lib/adapter.js:5920 |
which js-controller version you have running?
Reason is basically that javascript adapter uses getForeignStates to initialize current values, but this method do not support regex as id ...
I'm running 4.3.4 I found the issue on my own. Regex only works if you do not select "Do not subscribe on all states on startup". This was reproducible in my case. Can someone confirm this?
my infos above is kind of an confirmation. It can not work that way "code wise"
Why you close it? Needs to be fixed
Why you close it? Needs to be fixed
It is not a bug it is new feature.
It is because of https://github.com/ioBroker/ioBroker.js-controller/blob/master/lib/adapter.js#L6872
// read first the keys for pattern
let params = {};
if (pattern && pattern !== '*') {
params = {
startkey: pattern.replace(/\*/g, ''),
endkey: pattern.replace(/\*/g, '\u9999')
};
}