bitfocus / companion-module-generic-mqtt

MIT License
2 stars 4 forks source link

Variables are undefined on startup #21

Closed Nico96R closed 10 months ago

Nico96R commented 1 year ago

With the switch from 2.4.2 to the current beta, I experienced the following behavior of the module. Mqtt_variables are not initialized on module startup, therefore I only get $NA after a companion restart oder module restart. When I click on save config, every variable is being updated. I think I found the changed part, which creates this problem. This is from the companion debug log.

system: ** Connection started **
Starting up module class: GenericMqttInstance
Sentry disabled
Module-host accepted registration
debug: Successfully subscribed to topic: mqtt-module-test/retain
debug: MQTT message received: topic: mqtt-module-test/retain message: jaja nein
debug: Refreshing variable definitions:

When I change the following code (index.js), I get this debug message.

15  this.debounceUpdateInstanceVariables = debounceFn(this._updateInstanceVariables, {
16      wait: 0,
17      immediate: false,
18  })
system: ** Connection started **
Starting up module class: GenericMqttInstance
Sentry disabled
Module-host accepted registration
debug: Refreshing variable definitions:
debug: Successfully subscribed to topic: mqtt-module-test/retain
debug: MQTT message received: topic: mqtt-module-test/retain message: jaja nein

This time every thing works like it used to be. The message with setVariableValue is too early and the corresponding variable is not yet defined with the debounce of 100ms. I didn't find a quick way to fix this, without replacing the 100ms with 0ms. Maybe there is a better solution to this problem.

Nico96R commented 1 year ago

any information about this bug/feature?

Nico96R commented 1 year ago

still no comment on this bug?

Julusian commented 10 months ago

I havent been able to reproduce this, but I have made a hopeful fix so it should be fixed now