From d638bb4f58bf81c60ef218204b1fba75cf16b36a Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Mon, 26 Feb 2024 23:35:30 +0300 Subject: config changes --- bin/ipcam_capture.py | 3 +- bin/ipcam_ntp_util.py | 12 ++-- bin/ipcam_server.py | 3 +- include/py/hikvision/isapi.py | 4 +- include/py/homekit/camera/config.py | 3 +- include/py/homekit/camera/types.py | 10 +-- include/py/homekit/camera/util.py | 3 +- include/py/homekit/config/__init__.py | 4 -- include/py/homekit/config/_configs.py | 69 ------------------- include/py/homekit/linux/__init__.py | 2 + include/py/homekit/linux/config.py | 120 ++++++++++++++++++++++++++++++++++ include/py/homekit/linux/types.py | 25 +++++++ 12 files changed, 168 insertions(+), 90 deletions(-) delete mode 100644 include/py/homekit/config/_configs.py create mode 100644 include/py/homekit/linux/__init__.py create mode 100644 include/py/homekit/linux/config.py create mode 100644 include/py/homekit/linux/types.py diff --git a/bin/ipcam_capture.py b/bin/ipcam_capture.py index 226e12e..25b101d 100755 --- a/bin/ipcam_capture.py +++ b/bin/ipcam_capture.py @@ -10,7 +10,8 @@ from typing import TextIO from argparse import ArgumentParser from socket import gethostname from asyncio.streams import StreamReader -from homekit.config import LinuxBoardsConfig, config as homekit_config +from homekit.config import config as homekit_config +from homekit.linux import LinuxBoardsConfig from homekit.camera import IpcamConfig, CaptureType from homekit.camera.util import get_hls_directory, get_hls_channel_name, get_recordings_path diff --git a/bin/ipcam_ntp_util.py b/bin/ipcam_ntp_util.py index 077b00c..0461cc2 100755 --- a/bin/ipcam_ntp_util.py +++ b/bin/ipcam_ntp_util.py @@ -39,7 +39,7 @@ def process_camera(host: str, except hikvision.ResponseError as e: print(f'[{host}] ({str(e)})') - elif camera_type.is_ali(): + elif camera_type.is_xmeye(): try: client = xmeye.XMEyeCamera(hostname=host, username=login, password=password) client.login() @@ -56,7 +56,7 @@ def process_camera(host: str, def main(): - camera_types = ['hikvision', 'ali'] + camera_types = ['hikvision', 'xmeye'] parser = ArgumentParser() parser.add_argument('--camera', type=str) parser.add_argument('--camera-type', type=str, choices=camera_types) @@ -100,8 +100,8 @@ def main(): if args.camera_type == 'hikvision': camera_type = CameraType.HIKVISION_264 - elif args.camera_type == 'ali': - camera_type = CameraType.ALIEXPRESS_NONAME + elif args.camera_type == 'xmeye': + camera_type = CameraType.XMEYE else: raise ValueError('invalid --camera-type') process_camera(camera_host, action, login, password, camera_type, **kwargs) @@ -113,10 +113,10 @@ def main(): cam_type = ipcam_config.get_camera_type(cam) if args.all_of_type == 'hikvision' and not cam_type.is_hikvision(): continue - if args.all_of_type == 'ali' and not ipcam_config.get_camera_type(cam).is_ali(): + if args.all_of_type == 'xmeye' and not ipcam_config.get_camera_type(cam).is_xmeye(): continue process_camera(ipcam_config.get_camera_ip(cam), action, login, password, cam_type, **kwargs) if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/bin/ipcam_server.py b/bin/ipcam_server.py index 71d5ea1..cb2711c 100755 --- a/bin/ipcam_server.py +++ b/bin/ipcam_server.py @@ -13,7 +13,8 @@ from argparse import ArgumentParser from apscheduler.schedulers.asyncio import AsyncIOScheduler from asyncio import Lock -from homekit.config import config as homekit_config, LinuxBoardsConfig +from homekit.config import config as homekit_config +from homekit.linux import LinuxBoardsConfig from homekit.util import Addr from homekit import http from homekit.database.sqlite import SQLiteBase diff --git a/include/py/hikvision/isapi.py b/include/py/hikvision/isapi.py index 6cc34f8..c5b5266 100644 --- a/include/py/hikvision/isapi.py +++ b/include/py/hikvision/isapi.py @@ -2,8 +2,8 @@ import requests from time import time from .util import xml_to_dict, sha256_hex -from ...util import validate_ipv4 -from ...http import HTTPMethod +from homekit.util import validate_ipv4 +from homekit.http import HTTPMethod from typing import Optional, Union diff --git a/include/py/homekit/camera/config.py b/include/py/homekit/camera/config.py index 257e5f1..93bd8f9 100644 --- a/include/py/homekit/camera/config.py +++ b/include/py/homekit/camera/config.py @@ -1,6 +1,7 @@ import socket -from ..config import ConfigUnit, LinuxBoardsConfig +from ..config import ConfigUnit +from ..linux import LinuxBoardsConfig from typing import Optional from .types import CameraType, VideoContainerType, VideoCodecType diff --git a/include/py/homekit/camera/types.py b/include/py/homekit/camera/types.py index 0aaadef..aa35ebf 100644 --- a/include/py/homekit/camera/types.py +++ b/include/py/homekit/camera/types.py @@ -13,7 +13,7 @@ class VideoCodecType(Enum): class CameraType(Enum): ESP32 = 'esp32' - ALIEXPRESS_NONAME = 'ali' + XMEYE = 'xmeye' HIKVISION_264 = 'hik_264' HIKVISION_265 = 'hik_265' @@ -25,7 +25,7 @@ class CameraType(Enum): elif channel == 2: if self.is_hikvision(): return '/Streaming/Channels/2' - elif self.value == CameraType.ALIEXPRESS_NONAME: + elif self.value == CameraType.XMEYE: return '/?stream=1.sdp' else: raise ValueError(f'unsupported camera type {self.value}') @@ -34,7 +34,7 @@ class CameraType(Enum): if channel == 1: return VideoCodecType.H264 if self.value == CameraType.HIKVISION_264 else VideoCodecType.H265 elif channel == 2: - return VideoCodecType.H265 if self.value == CameraType.ALIEXPRESS_NONAME else VideoCodecType.H264 + return VideoCodecType.H265 if self.value == CameraType.XMEYE else VideoCodecType.H264 else: raise ValueError(f'unexpected channel {channel}') @@ -44,8 +44,8 @@ class CameraType(Enum): def is_hikvision(self) -> bool: return self in (CameraType.HIKVISION_264, CameraType.HIKVISION_265) - def is_ali(self) -> bool: - return self == CameraType.ALIEXPRESS_NONAME + def is_xmeye(self) -> bool: + return self == CameraType.XMEYE class TimeFilterType(Enum): diff --git a/include/py/homekit/camera/util.py b/include/py/homekit/camera/util.py index 58c2c70..6b54129 100644 --- a/include/py/homekit/camera/util.py +++ b/include/py/homekit/camera/util.py @@ -7,7 +7,8 @@ import re from datetime import datetime from typing import List, Tuple from ..util import chunks -from ..config import config, LinuxBoardsConfig +from ..config import config +from ..linux import LinuxBoardsConfig from .config import IpcamConfig from .types import VideoContainerType diff --git a/include/py/homekit/config/__init__.py b/include/py/homekit/config/__init__.py index 6323697..292167b 100644 --- a/include/py/homekit/config/__init__.py +++ b/include/py/homekit/config/__init__.py @@ -8,8 +8,4 @@ from .config import ( is_development_mode, setup_logging, CONFIG_DIRECTORIES -) -from ._configs import ( - LinuxBoardsConfig, - ServicesListConfig ) \ No newline at end of file diff --git a/include/py/homekit/config/_configs.py b/include/py/homekit/config/_configs.py deleted file mode 100644 index 43af25a..0000000 --- a/include/py/homekit/config/_configs.py +++ /dev/null @@ -1,69 +0,0 @@ -from .config import ConfigUnit -from typing import Optional - - -class ServicesListConfig(ConfigUnit): - NAME = 'services_list' - - @classmethod - def schema(cls) -> Optional[dict]: - return { - 'type': 'list', - 'empty': False, - 'schema': { - 'type': 'string' - } - } - - -class LinuxBoardsConfig(ConfigUnit): - NAME = 'linux_boards' - - @classmethod - def schema(cls) -> Optional[dict]: - return { - 'type': 'dict', - 'schema': { - # 'mdns': {'type': 'string', 'required': True}, - 'board': {'type': 'string', 'required': True}, - 'location': {'type': 'string', 'required': True}, - 'mac': cls._addr_schema(mac=True, required=False), # FIXME mac should be required field - 'network': { - 'type': 'list', - 'required': True, - 'empty': False, - 'allowed': ['wifi', 'ethernet'] - }, - 'ram': {'type': 'integer', 'required': False}, # FIXME same as below - 'online': {'type': 'boolean', 'required': False}, # FIXME made required=False temporarily, should be always required I guess - - # optional - 'services': { - 'type': 'list', - 'empty': False, - 'allowed': ServicesListConfig().get() - }, - 'ext_hdd': { - 'type': 'list', - 'schema': { - 'type': 'dict', - 'schema': { - 'mountpoint': {'type': 'string', 'required': True}, - 'size': {'type': 'integer', 'required': True} - } - }, - }, - 'misc': { - 'type': 'dict', - 'schema': { - 'case': {'type': 'string', 'allowed': ['metal', 'plastic']} - } - }, - } - } - - def get_board_disks(self, name: str) -> list[dict]: - return self[name]['ext_hdd'] - - def get_board_disks_count(self, name: str) -> int: - return len(self[name]['ext_hdd']) diff --git a/include/py/homekit/linux/__init__.py b/include/py/homekit/linux/__init__.py new file mode 100644 index 0000000..8b9f2ce --- /dev/null +++ b/include/py/homekit/linux/__init__.py @@ -0,0 +1,2 @@ +from .config import LinuxBoardsConfig +from .types import LinuxBoardType diff --git a/include/py/homekit/linux/config.py b/include/py/homekit/linux/config.py new file mode 100644 index 0000000..9321e28 --- /dev/null +++ b/include/py/homekit/linux/config.py @@ -0,0 +1,120 @@ +from ..config import ConfigUnit +from .types import LinuxBoardType +from typing import Optional + + +class ServicesListConfig(ConfigUnit): + NAME = 'services_list' + + @classmethod + def schema(cls) -> Optional[dict]: + return { + 'type': 'dict', + 'schema': { + 'system': dict(type='boolean'), + 'exec': dict(type='string'), + 'root': dict(type='boolean'), + 'after': dict(type='string'), + 'cron': { + 'type': 'dict', + 'schema': { + 'time': dict(type='string', required=True), + 'exec': dict(type='string', required=True), + 'args': dict(type='string'), + } + } + } + } + + @classmethod + def validate(self): + pass + + +class LinuxBoardsConfig(ConfigUnit): + NAME = 'linux_boards' + + @classmethod + def schema(cls) -> Optional[dict]: + services_list = list(ServicesListConfig().keys()) + return { + 'type': 'dict', + 'schema': { + 'board': { + 'type': 'string', + 'required': True, + 'allowed': [t.value for t in LinuxBoardType] + }, + 'role': {'type': 'string', 'required': False}, + 'location': {'type': 'string', 'required': True}, + 'notes': {'type': 'string', 'required': False}, + + 'network': { + 'type': 'dict', + 'schema': { + 'ethernet': cls._network_device_schema(), + 'wifi': cls._network_device_schema(), + } + }, + 'online': {'type': 'boolean', 'required': False}, + + 'services': { + 'type': 'list', + 'schema': { + 'oneof': [ + {'type': 'string', 'allowed': services_list}, + { + 'type': 'dict', + 'schema': { + 'keyschema': { + 'type': 'string', + 'allowed': services_list + } + }, + 'allow_unknown': True + } + ] + + } + }, + + 'ext_hdd': { + 'type': 'list', + 'schema': { + 'type': 'dict', + 'schema': { + 'mountpoint': {'type': 'string', 'required': True}, + 'size': {'type': 'integer', 'required': True}, + 'uuid': { + 'type': 'string', + 'regex': '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$', + 'required': True + }, + 'ssd': {'required': False, 'type': 'boolean'} + } + }, + } + } + } + + @classmethod + def _network_device_schema(cls, required=False) -> dict: + return { + 'type': 'list', + 'required': required, + 'schema': { + 'type': 'dict', + 'schema': { + 'mac': cls._addr_schema(mac=True, required=True), + 'mac_fake': {'type': 'boolean', 'required': False}, + 'ip': cls._addr_schema(only_ip=True, required=True), + 'usb': {'type': 'boolean', 'required': False} + } + } + } + + def get_board_disks(self, name: str) -> list[dict]: + return self[name]['ext_hdd'] + + def get_board_disks_count(self, name: str) -> int: + return len(self[name]['ext_hdd']) diff --git a/include/py/homekit/linux/types.py b/include/py/homekit/linux/types.py new file mode 100644 index 0000000..2b934c7 --- /dev/null +++ b/include/py/homekit/linux/types.py @@ -0,0 +1,25 @@ +from enum import Enum + + +class LinuxBoardType(Enum): + ORANGE_PI_ONE = 'opione' + ORANGE_PI_ONE_PLUS = 'opioneplus' + ORANGE_PI_LITE = 'opilite' + ORANGE_PI_ZERO = 'opizero' + ORANGE_PI_ZERO2 = 'opizero2' + ORANGE_PI_PC = 'opipc' + ORANGE_PI_PC2 = 'opipc2' + ORANGE_PI_3 = 'opi3' + ORANGE_PI_3_LTS = 'opi3lts' + ORANGE_PI_5 = 'opi5' + + @property + def ram(self) -> int: + if self in (LinuxBoardType.ORANGE_PI_ONE, LinuxBoardType.ORANGE_PI_LITE, LinuxBoardType.ORANGE_PI_ZERO): + return 512 + elif self in (LinuxBoardType.ORANGE_PI_ZERO2, LinuxBoardType.ORANGE_PI_PC, LinuxBoardType.ORANGE_PI_PC2, LinuxBoardType.ORANGE_PI_ONE_PLUS): + return 1024 + elif self in (LinuxBoardType.ORANGE_PI_3, LinuxBoardType.ORANGE_PI_3_LTS): + return 2048 + elif self in (LinuxBoardType.ORANGE_PI_5,): + return 8192 -- cgit v1.2.3