diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2024-02-26 23:35:30 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2024-02-26 23:35:30 +0300 |
commit | d638bb4f58bf81c60ef218204b1fba75cf16b36a (patch) | |
tree | fe722115fb639aa8958d10dd6c5094db679826be /include/py/homekit/linux | |
parent | c4f87ddad4058c0f331446fdfd8d762b8fc26c18 (diff) |
config changes
Diffstat (limited to 'include/py/homekit/linux')
-rw-r--r-- | include/py/homekit/linux/__init__.py | 2 | ||||
-rw-r--r-- | include/py/homekit/linux/config.py | 120 | ||||
-rw-r--r-- | include/py/homekit/linux/types.py | 25 |
3 files changed, 147 insertions, 0 deletions
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 |