This commit is contained in:
avollkopf 2023-04-01 14:13:04 +02:00
parent 35252a2b83
commit 7fa738d240
4 changed files with 30 additions and 8 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.1.7" __version__ = "4.1.8.a1"
__codename__ = "Groundhog Day" __codename__ = "Groundhog Day"

View file

@ -199,11 +199,12 @@ class Config:
description: str = None description: str = None
type: ConfigType = ConfigType.STRING type: ConfigType = ConfigType.STRING
options: Any = None options: Any = None
source: str = None
def __str__(self): def __str__(self):
return "....name={} value={}".format(self.name, self.value) return "....name={} value={}".format(self.name, self.value)
def to_dict(self): def to_dict(self):
return dict(name=self.name, value=self.value, type=self.type.value, description=self.description, options=self.options) return dict(name=self.name, value=self.value, type=self.type.value, description=self.description, options=self.options, source=self.source)
@dataclass @dataclass
class NotificationAction: class NotificationAction:

View file

@ -19,21 +19,18 @@ class ConfigController:
self.path_static = cbpi.config_folder.get_file_path("config.yaml") self.path_static = cbpi.config_folder.get_file_path("config.yaml")
self.logger.info("Config folder path : " + os.path.join(Path(self.cbpi.config_folder.configFolderPath).absolute())) self.logger.info("Config folder path : " + os.path.join(Path(self.cbpi.config_folder.configFolderPath).absolute()))
def get_state(self): def get_state(self):
result = {} result = {}
for key, value in self.cache.items(): for key, value in self.cache.items():
result[key] = value.to_dict() result[key] = value.to_dict()
return result
return result
async def init(self): async def init(self):
self.static = load_config(self.path_static) self.static = load_config(self.path_static)
with open(self.path) as json_file: with open(self.path) as json_file:
data = json.load(json_file) data = json.load(json_file)
for key, value in data.items(): for key, value in data.items():
self.cache[key] = Config(name=value.get("name"), value=value.get("value"), description=value.get("description"), type=ConfigType(value.get("type", "string")), options=value.get("options", None) ) self.cache[key] = Config(name=value.get("name"), value=value.get("value"), description=value.get("description"), type=ConfigType(value.get("type", "string")), options=value.get("options", None), source=value.get("source", "craftbeerpi") )
def get(self, name, default=None): def get(self, name, default=None):
self.logger.debug("GET CONFIG VALUE %s (default %s)" % (name, default)) self.logger.debug("GET CONFIG VALUE %s (default %s)" % (name, default))

View file

@ -205,6 +205,7 @@ class PluginController():
from importlib.metadata import (distribution, metadata, from importlib.metadata import (distribution, metadata,
version) version)
meta = metadata(key) meta = metadata(key)
logging.warning(key)
result.append({row: meta[row] result.append({row: meta[row]
for row in list(metadata(key))}) for row in list(metadata(key))})
except Exception as e: except Exception as e:
@ -215,3 +216,26 @@ class PluginController():
logger.error(e) logger.error(e)
return [] return []
return result return result
async def load_plugin_names(self, filter="cbpi"):
result = []
result.append(dict(Name="craftbeerpi"))
try:
discovered_plugins = {
name: importlib.import_module(name)
for finder, name, ispkg
in pkgutil.iter_modules()
if name.startswith('cbpi') and len(name) > 4
}
for key, module in discovered_plugins.items():
try:
meta = metadata(key)
result.append(dict(Name=meta["Name"]))
except Exception as e:
logger.error("FAILED to load plugin {} ".format(key))
logger.error(e)
except Exception as e:
logger.error(e)
return result
return result