|
12 | 12 | from . import utils |
13 | 13 | from .app_management import UpdateMode |
14 | 14 | from .models.config.plugin import PluginConfig |
| 15 | +from .models.config import AppConfig |
15 | 16 |
|
16 | 17 | if TYPE_CHECKING: |
17 | | - from appdaemon.appdaemon import AppDaemon |
| 18 | + from .adapi import ADAPI |
| 19 | + from .appdaemon import AppDaemon |
18 | 20 |
|
19 | 21 |
|
20 | 22 | class PluginBase(abc.ABC): |
@@ -282,13 +284,13 @@ def __init__(self, ad: "AppDaemon", config: dict[str, PluginConfig]): |
282 | 284 | self.logger.info( |
283 | 285 | msg, |
284 | 286 | name, |
285 | | - cfg.class_name, |
286 | | - cfg.module_name, |
| 287 | + cfg.plugin_class, |
| 288 | + cfg.plugin_module, |
287 | 289 | ) |
288 | 290 |
|
289 | 291 | try: |
290 | | - module = importlib.import_module(cfg.module_name) |
291 | | - plugin_class: Type[PluginBase] = getattr(module, cfg.class_name) |
| 292 | + module = importlib.import_module(cfg.plugin_module) |
| 293 | + plugin_class: Type[PluginBase] = getattr(module, cfg.plugin_class) |
292 | 294 | plugin: PluginBase = plugin_class(self.AD, name, self.config[name]) |
293 | 295 | namespace = plugin.config.namespace |
294 | 296 |
|
@@ -486,19 +488,12 @@ def required_meta_check(self): |
486 | 488 | OK = False |
487 | 489 | return OK |
488 | 490 |
|
489 | | - async def get_plugin_api(self, plugin_name, name, _logging, args, config, app_config, global_vars): |
490 | | - if plugin_name in self.config: |
491 | | - plugin = self.config[plugin_name] |
492 | | - module_name = "{}api".format(plugin["type"]) |
493 | | - mod = __import__(module_name, globals(), locals(), [module_name], 0) |
494 | | - app_class = getattr(mod, plugin["type"].title()) |
495 | | - api = app_class(self.AD, name, _logging, args, config, app_config, global_vars) |
496 | | - if "namespace" in plugin: |
497 | | - api.set_namespace(plugin["namespace"]) |
498 | | - else: |
499 | | - api.set_namespace("default") |
| 491 | + def get_plugin_api(self, plugin_name: str, app_cfg: AppConfig) -> "ADAPI": |
| 492 | + if plugin_cfg := self.config.get(plugin_name): |
| 493 | + module = importlib.import_module(plugin_cfg.api_module) |
| 494 | + api_class: Type["ADAPI"] = getattr(module, plugin_cfg.api_class) |
| 495 | + api = api_class(self.AD, app_cfg) |
| 496 | + api.set_namespace(plugin_cfg.namespace) |
500 | 497 | return api |
501 | | - |
502 | 498 | else: |
503 | 499 | self.logger.warning("Unknown Plugin Configuration in get_plugin_api()") |
504 | | - return None |
0 commit comments