Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribe by Regex with option 'Do not subscribe all states on start' #1401

Open
om2804 opened this issue Sep 6, 2023 · 6 comments
Open

Comments

@om2804
Copy link

om2804 commented Sep 6, 2023

Describe the bug
Not receiving messages after subscribing with regex. Option 'Do not subscribe all states on start' is true.
Similar to issue #1311

To Reproduce
Steps to reproduce the behavior:

  1. Go to setting adapter
  2. Set option 'Do not subscribe all states on start' as true.
  3. Create and run script (for example)
on(new RegExp("mqtt.0.zigbee2mqtt.*"), cs => {
        log(cs.state.val); // never :(
    });
  1. Change state mqtt.0.zigbee2mqtt.*

Expected behavior
Messages are coming.

Versions:

  • Adapter version: 7.1.4
  • JS-Controller version: 4.0.24
  • Node version: 16
  • Operating system: Linux
@Apollon77
Copy link
Contributor

Mal unabhängig vom issue ... dir ist klar das man zb "." in Regex escapen muss? Was du dfa hast ist eher ein "Pattern" und weniger eine regex ...

@om2804
Copy link
Author

om2804 commented Sep 6, 2023

Mal unabhängig vom issue ... dir ist klar das man zb "." in Regex escapen muss? Was du dfa hast ist eher ein "Pattern" und weniger eine regex ...

I understand. Just an example
new RegExp("mqtt\.0\.zigbee2mqtt\..*")

@HSE83
Copy link

HSE83 commented Apr 23, 2024

Is there a suggested workaround for this issue? Iterate all states by using $[...], registering a single callback for each of the matches?

@HSE83
Copy link

HSE83 commented Apr 24, 2024

Okay, a practical solution is the following code:

$("mqtt.0.zigbee2mqtt.*").on(function(cs) {
// Use this instead of the original function OR in addition if you rely on a more complex regexp
});

As soon as this is added, more complicated regular expressions also work - as long as they are covered by the wildcard in the workaround. So the problem might be due to js-controller not being able to work with regular expressions?

@klein0r
Copy link
Collaborator

klein0r commented May 8, 2024

I think this is related to #525

The problem is, that the subscribeForeignState function doesn't support regular expressions.

adapter.subscribeForeignStates(pattern);

@Apollon77
Copy link
Contributor

Thats indeed completely right.

So easiest solution is to "throw" an error if someone tries to subscribe regex when not all states are subscribed. In fact my main question would by why someone turned off the auto subscription ... this is "advanced feature" in my eyes which should be only used well-thought.

The alterative is very meehhh because it would require to somehow "convert" the given regex pattern into a "iobroker wildcard pattern string" (kind of only "*" and "?" allowed) ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants