Context: I'm trying to fix this regression for the Victron Venus OS, which is caused by a regression in node-red-contrib-victron.
Note that this is not a node-red bug or regression.
The issue is related to creating a config node on demand, when receiving the onadd
event: With a pristine install, when importing a flow through the "Import nodes > Paste flow json" feature, the onadd
callback never triggers, which is expected. Therefore, however, the import creates nodes that cannot be configured, because the config node they depend upon never got created. (On the server side, the config instantiates a dbus client and sets up caching etc, which many of the victron node-red nodes depend on.)
What I have so far is an ugly solution, where I sleep for a bit, and then trigger the creation of the config node. Having to sleep is necessary, as otherwise RED.nodes.eachConfig()
won't include the config node: the state in the browser does not seem to know the config node yet (even once it has been deployed). Sleeping a little solves this, but it is a brittle solution, as the sleep duration may not be enough in some scenarios (slow server side?).
My questions:
-
In order to avoid the "sleep-for-a-bit" solution, is there an event or other mechanism I can use to ensure I run logic only once all existing (deployed) config nodes are known to
RED.nodes.eachConfig()
? -
Are we doing this wrong (how we create the config node)? I guess we are doing it wrong, the approach suggested in an older discussion seems cleaner. But, could we actually migrate to the cleaner solution in a way that the import works? We would want the import to work for existing flows that do not reference config nodes at all.
Am I missing something? I know that I lack some context related to undeployed / deployed flows, and maybe many other things, which may be relevant here; can anyone point me in the right direction?
P.S. As a new user I am apparently allowed 2 links only. If you allow me to add more links, I'll link more of the code, or do you want me to add relevant code snippets into the topic, rather?