config changes
This commit is contained in:
parent
c4f87ddad4
commit
d638bb4f58
@ -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
|
||||
|
||||
|
@ -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()
|
||||
main()
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
||||
|
@ -8,8 +8,4 @@ from .config import (
|
||||
is_development_mode,
|
||||
setup_logging,
|
||||
CONFIG_DIRECTORIES
|
||||
)
|
||||
from ._configs import (
|
||||
LinuxBoardsConfig,
|
||||
ServicesListConfig
|
||||
)
|
@ -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'])
|
2
include/py/homekit/linux/__init__.py
Normal file
2
include/py/homekit/linux/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from .config import LinuxBoardsConfig
|
||||
from .types import LinuxBoardType
|
120
include/py/homekit/linux/config.py
Normal file
120
include/py/homekit/linux/config.py
Normal file
@ -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'])
|
25
include/py/homekit/linux/types.py
Normal file
25
include/py/homekit/linux/types.py
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user