-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Live loading of external JS (converters/extensions) (#24764)
* feat: Live loading of external JS (converters/extensions) * Fix imports * Improve error message on MQTT save * Handle non-existing base path * Throw on bad converter * Add tests * Fix use of ext conv in network map tests. * More coverage. * Dont mock zhc for basics, tests actual live loading * Update * feat: Live loading of external JS (converters/extensions) * Fix imports * Improve error message on MQTT save * Handle non-existing base path * Throw on bad converter * Add tests * Fix use of ext conv in network map tests. * More coverage. * Dont mock zhc for basics, tests actual live loading * Update * Fix rebase * Fix * Bump zhc * pretty * fix typing * Cleanup `external_converters` setting remnants. --------- Co-authored-by: Koen Kanters <[email protected]>
- Loading branch information
Showing
22 changed files
with
750 additions
and
477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type Extension from './extension'; | ||
|
||
import logger from '../util/logger'; | ||
import * as settings from '../util/settings'; | ||
import ExternalJSExtension from './externalJS'; | ||
|
||
type ModuleExports = typeof Extension; | ||
|
||
export default class ExternalExtensions extends ExternalJSExtension<ModuleExports> { | ||
constructor( | ||
zigbee: Zigbee, | ||
mqtt: MQTT, | ||
state: State, | ||
publishEntityState: PublishEntityState, | ||
eventBus: EventBus, | ||
enableDisableExtension: (enable: boolean, name: string) => Promise<void>, | ||
restartCallback: () => Promise<void>, | ||
addExtension: (extension: Extension) => Promise<void>, | ||
) { | ||
super( | ||
zigbee, | ||
mqtt, | ||
state, | ||
publishEntityState, | ||
eventBus, | ||
enableDisableExtension, | ||
restartCallback, | ||
addExtension, | ||
'extension', | ||
'external_extensions', | ||
); | ||
} | ||
|
||
protected async removeJS(name: string, module: ModuleExports): Promise<void> { | ||
await this.enableDisableExtension(false, module.name); | ||
} | ||
|
||
protected async loadJS(name: string, module: ModuleExports): Promise<void> { | ||
// stop if already started | ||
await this.enableDisableExtension(false, module.name); | ||
await this.addExtension( | ||
// @ts-expect-error `module` is the interface, not the actual passed class | ||
new module( | ||
this.zigbee, | ||
this.mqtt, | ||
this.state, | ||
this.publishEntityState, | ||
this.eventBus, | ||
this.enableDisableExtension, | ||
this.restartCallback, | ||
this.addExtension, | ||
settings, | ||
logger, | ||
), | ||
); | ||
|
||
logger.info(`Loaded external extension '${name}'.`); | ||
} | ||
} |
Oops, something went wrong.