summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/py/homekit/config/config.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/include/py/homekit/config/config.py b/include/py/homekit/config/config.py
index 29364af..773de1e 100644
--- a/include/py/homekit/config/config.py
+++ b/include/py/homekit/config/config.py
@@ -52,6 +52,8 @@ class BaseConfigUnit(ABC):
def load_from(self, path: str):
with open(path, 'r') as fd:
self._data = yaml.safe_load(fd)
+ if self._data is None:
+ raise TypeError(f'config file {path} is empty')
def get(self,
key: Optional[str] = None,
@@ -78,6 +80,10 @@ class ConfigUnit(BaseConfigUnit):
_instance = None
+ def __init_subclass__(cls, **kwargs):
+ super().__init_subclass__(**kwargs)
+ cls._instance = None
+
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(ConfigUnit, cls).__new__(cls, *args, **kwargs)
@@ -200,7 +206,7 @@ class AppConfigUnit(ConfigUnit):
def logging_get_fmt(self) -> Optional[str]:
try:
return self['logging']['default_fmt']
- except KeyError:
+ except (KeyError, TypeError):
return self._logging_fmt
def logging_set_file(self, file: str) -> None:
@@ -209,7 +215,7 @@ class AppConfigUnit(ConfigUnit):
def logging_get_file(self) -> Optional[str]:
try:
return self['logging']['file']
- except KeyError:
+ except (KeyError, TypeError):
return self._logging_file
def logging_set_verbose(self):
@@ -218,7 +224,7 @@ class AppConfigUnit(ConfigUnit):
def logging_is_verbose(self) -> bool:
try:
return bool(self['logging']['verbose'])
- except KeyError:
+ except (KeyError, TypeError):
return self._logging_verbose
@@ -271,7 +277,9 @@ class Config:
and not isinstance(name, bool) \
and issubclass(name, AppConfigUnit) or name == AppConfigUnit:
self.app_name = name.NAME
+ print(self.app_config)
self.app_config = name()
+ print(self.app_config)
app_config = self.app_config
else:
self.app_name = name if isinstance(name, str) else None