From 7058d0f5063dc9b065248d0a906cf874788caecf Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Wed, 13 Sep 2023 09:34:49 +0300 Subject: save --- include/py/homekit/config/config.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'include/py/homekit/config/config.py') diff --git a/include/py/homekit/config/config.py b/include/py/homekit/config/config.py index 5fe1ae8..abdedad 100644 --- a/include/py/homekit/config/config.py +++ b/include/py/homekit/config/config.py @@ -41,6 +41,9 @@ class BaseConfigUnit(ABC): self._data = {} self._logger = logging.getLogger(self.__class__.__name__) + def __iter__(self): + return iter(self._data) + def __getitem__(self, key): return self._data[key] @@ -123,10 +126,10 @@ class ConfigUnit(BaseConfigUnit): return None @classmethod - def _addr_schema(cls, required=False, **kwargs): + def _addr_schema(cls, required=False, only_ip=False, **kwargs): return { 'type': 'addr', - 'coerce': Addr.fromstring, + 'coerce': Addr.fromstring if not only_ip else Addr.fromipstring, 'required': required, **kwargs } @@ -158,6 +161,7 @@ class ConfigUnit(BaseConfigUnit): pass v = MyValidator() + need_document = False if rst == RootSchemaType.DICT: normalized = v.validated({'document': self._data}, @@ -165,16 +169,21 @@ class ConfigUnit(BaseConfigUnit): 'type': 'dict', 'keysrules': {'type': 'string'}, 'valuesrules': schema - }})['document'] + }}) + need_document = True elif rst == RootSchemaType.LIST: v = MyValidator() - normalized = v.validated({'document': self._data}, {'document': schema})['document'] + normalized = v.validated({'document': self._data}, {'document': schema}) + need_document = True else: normalized = v.validated(self._data, schema) if not normalized: raise cerberus.DocumentError(f'validation failed: {v.errors}') + if need_document: + normalized = normalized['document'] + self._data = normalized try: @@ -235,6 +244,8 @@ class TranslationUnit(BaseConfigUnit): class Translation: LANGUAGES = ('en', 'ru') + DEFAULT_LANGUAGE = 'ru' + _langs: dict[str, TranslationUnit] def __init__(self, name: str): @@ -278,9 +289,7 @@ 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 -- cgit v1.2.3 From da5db8bc280deab0e2081f39d2f32aabb2372afe Mon Sep 17 00:00:00 2001 From: Evgeny Sorokin Date: Tue, 16 Jan 2024 02:05:00 +0300 Subject: wip --- include/py/homekit/config/config.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/py/homekit/config/config.py') diff --git a/include/py/homekit/config/config.py b/include/py/homekit/config/config.py index abdedad..eb2ad82 100644 --- a/include/py/homekit/config/config.py +++ b/include/py/homekit/config/config.py @@ -78,6 +78,9 @@ class BaseConfigUnit(ABC): raise KeyError(f'option {key} not found') + def getkeys(self): + return list(self._data.keys()) + class ConfigUnit(BaseConfigUnit): NAME = 'dumb' -- cgit v1.2.3 From d237e81873a9e043f579e7f6a979f00510ddce08 Mon Sep 17 00:00:00 2001 From: Evgeny Sorokin Date: Thu, 18 Jan 2024 04:14:38 +0300 Subject: lws: sms page rewrite --- include/py/homekit/config/config.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'include/py/homekit/config/config.py') diff --git a/include/py/homekit/config/config.py b/include/py/homekit/config/config.py index eb2ad82..fec92a6 100644 --- a/include/py/homekit/config/config.py +++ b/include/py/homekit/config/config.py @@ -78,8 +78,14 @@ class BaseConfigUnit(ABC): raise KeyError(f'option {key} not found') - def getkeys(self): - return list(self._data.keys()) + def values(self): + return self._data.values() + + def keys(self): + return self._data.keys() + + def items(self): + return self._data.items() class ConfigUnit(BaseConfigUnit): -- cgit v1.2.3