summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2024-02-18 01:35:57 +0300
committerEvgeny Zinoviev <me@ch1p.io>2024-02-18 01:35:57 +0300
commit42155370475b1f6619498ec2c43c1c7f328ce1a1 (patch)
treeaa7a708bb94362e0c79d7f3678d07883baa4ba76 /include
parent70b4a4f044cac8052bb0af7c585572e54489ea2f (diff)
lws: wip
Diffstat (limited to 'include')
-rw-r--r--include/py/homekit/camera/config.py7
-rw-r--r--include/py/homekit/config/config.py16
-rw-r--r--include/py/homekit/util.py4
3 files changed, 22 insertions, 5 deletions
diff --git a/include/py/homekit/camera/config.py b/include/py/homekit/camera/config.py
index 9685cab..bcd5d07 100644
--- a/include/py/homekit/camera/config.py
+++ b/include/py/homekit/camera/config.py
@@ -44,7 +44,7 @@ class IpcamConfig(ConfigUnit):
}
}
},
- 'areas': {
+ 'zones': {
'type': 'dict',
'keysrules': {'type': 'string'},
'valuesrules': {
@@ -114,11 +114,14 @@ class IpcamConfig(ConfigUnit):
# FIXME
def get_all_cam_names(self,
filter_by_server: Optional[str] = None,
- filter_by_disk: Optional[int] = None) -> list[int]:
+ filter_by_disk: Optional[int] = None,
+ only_enabled=True) -> list[int]:
cams = []
if filter_by_server is not None and filter_by_server not in _lbc:
raise ValueError(f'invalid filter_by_server: {filter_by_server} not found in {_lbc.__class__.__name__}')
for cam, params in self['cameras'].items():
+ if only_enabled and not self.is_camera_enabled(cam):
+ continue
if filter_by_server is None or params['server'] == filter_by_server:
if filter_by_disk is None or params['disk'] == filter_by_disk:
cams.append(int(cam))
diff --git a/include/py/homekit/config/config.py b/include/py/homekit/config/config.py
index 40ac211..3aa0e04 100644
--- a/include/py/homekit/config/config.py
+++ b/include/py/homekit/config/config.py
@@ -266,14 +266,26 @@ class TranslationUnit(BaseConfigUnit):
pass
+TranslationInstances = {}
+
+
class Translation:
LANGUAGES = ('en', 'ru')
DEFAULT_LANGUAGE = 'ru'
_langs: dict[str, TranslationUnit]
+ # def __init_subclass__(cls, **kwargs):
+ # super().__init_subclass__(**kwargs)
+ # cls._instance = None
+
+ def __new__(cls, *args, **kwargs):
+ unit = args[0]
+ if unit not in TranslationInstances:
+ TranslationInstances[unit] = super(Translation, cls).__new__(cls)
+ return TranslationInstances[unit]
+
def __init__(self, name: str):
- super().__init__()
self._langs = {}
for lang in self.LANGUAGES:
for dirname in CONFIG_DIRECTORIES:
@@ -289,7 +301,7 @@ class Translation:
if len(diff) > 0:
raise RuntimeError(f'{name}: translation units have difference in keys: ' + ', '.join(diff))
- def get(self, lang: str) -> TranslationUnit:
+ def get(self, lang: str = DEFAULT_LANGUAGE) -> TranslationUnit:
return self._langs[lang]
diff --git a/include/py/homekit/util.py b/include/py/homekit/util.py
index 7732d3b..c686f29 100644
--- a/include/py/homekit/util.py
+++ b/include/py/homekit/util.py
@@ -12,7 +12,7 @@ import re
import os
import ipaddress
-from collections import namedtuple
+from collections.abc import KeysView
from enum import Enum
from datetime import datetime
from typing import Optional, List
@@ -119,6 +119,8 @@ def json_serial(obj):
return obj.timestamp()
if isinstance(obj, Enum):
return obj.value
+ if isinstance(obj, KeysView):
+ return list(obj)
raise TypeError("Type %s not serializable" % type(obj))