-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
User extensions are loaded multiple times, stop() is not called #9520
Comments
Changes will be available in the dev branch in a few hours from now. (https://www.zigbee2mqtt.io/advanced/more/switch-to-dev-branch.html) |
Just tried 1.22.0-dev commit: 2399ec0, which I believe should contain your fix, but the behavior is the same.
Thanks, this fixes the exception on exit. |
Ah, I see the class TestExtension {
constructor(zigbee, mqtt, state, publishEntityState, eventBus, settings, logger) {
logger.info('Loaded Test');
this.eventBus = eventBus;
this.eventBus.on('stateChange', this.onStateChange.bind(this), this);
}
async onStateChange(data) {
console.log("State changed Number 1");
}
async stop() {
console.log("async stop called");
this.eventBus.removeListeners(this);
}
}
module.exports = TestExtension; |
Indeed, it does! Thank you! |
What happened
When creating a user extension, changing and saving the extension in the web interface will cause the extension to be loaded multiple times. This is different to the behavior before the typescript refactor. The stop() function of the extension is not called.
What did you expect to happen
The extension should be stopped and the changed version should be loaded.
How to reproduce it (minimal and precise)
Install the attached test.js extension.
On every state change you will see "State changed Number 1" in the log.
Edit the extension with the web interface and save it:
async onStateChange(data) { console.log("State changed Number 2"); }
On every state change you will see "State changed Number 1" and "State changed Number 2" in the log.
Edit the extension with the web interface and save it:
async onStateChange(data) { console.log("State changed Number 3"); }
On every state change you will see "State changed Number 1", "State changed Number 2" and "State changed Number 3" in the log.
Note, that the stop() function is not called.
Related problem, if you exit z2m, stop() is called, but an exception is thrown:
´Failed to call 'TestExtension' 'stop' (TypeError: this.eventBus.removeListenersExtension is not a function
at TestExtension.stop (D:\NB\z2m\zigbee2mqtt\dist\util\externally-loaded.js:15:23)´
test.zip
See also: #7642
Debug info
Zigbee2MQTT version: 1.22.0-dev commit: a09aa42
Adapter hardware: CC26X2R1 (slaesh)
Adapter firmware version: 20210708
The text was updated successfully, but these errors were encountered: