summaryrefslogtreecommitdiff
path: root/include/py
diff options
context:
space:
mode:
Diffstat (limited to 'include/py')
-rw-r--r--include/py/hikvision/isapi.py4
-rw-r--r--include/py/homekit/camera/config.py3
-rw-r--r--include/py/homekit/camera/types.py10
-rw-r--r--include/py/homekit/camera/util.py3
-rw-r--r--include/py/homekit/config/__init__.py4
-rw-r--r--include/py/homekit/config/_configs.py69
-rw-r--r--include/py/homekit/linux/__init__.py2
-rw-r--r--include/py/homekit/linux/config.py120
-rw-r--r--include/py/homekit/linux/types.py25
9 files changed, 158 insertions, 82 deletions
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