summaryrefslogtreecommitdiff
path: root/include/py/homekit/config
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2024-02-17 03:51:08 +0300
committerEvgeny Zinoviev <me@ch1p.io>2024-02-17 03:51:08 +0300
commitc5e69cf2c9b89d546ad7a4f6bb26aef47021dd50 (patch)
tree61ea0185392909cf9d0198c51f439a2ee01e8089 /include/py/homekit/config
parent0ce2e41a2bad790c5232fafb4b6ed631ca8cd957 (diff)
ipcam_ntp_util (wip: only supports hikvision cams for now)
Diffstat (limited to 'include/py/homekit/config')
-rw-r--r--include/py/homekit/config/_configs.py13
-rw-r--r--include/py/homekit/config/config.py21
2 files changed, 28 insertions, 6 deletions
diff --git a/include/py/homekit/config/_configs.py b/include/py/homekit/config/_configs.py
index 2cd2aca..43af25a 100644
--- a/include/py/homekit/config/_configs.py
+++ b/include/py/homekit/config/_configs.py
@@ -24,17 +24,18 @@ class LinuxBoardsConfig(ConfigUnit):
return {
'type': 'dict',
'schema': {
- 'mdns': {'type': 'string', 'required': True},
+ # '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': True},
- 'online': {'type': 'boolean', 'required': True},
+ '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': {
@@ -52,6 +53,12 @@ class LinuxBoardsConfig(ConfigUnit):
}
},
},
+ 'misc': {
+ 'type': 'dict',
+ 'schema': {
+ 'case': {'type': 'string', 'allowed': ['metal', 'plastic']}
+ }
+ },
}
}
diff --git a/include/py/homekit/config/config.py b/include/py/homekit/config/config.py
index fec92a6..40ac211 100644
--- a/include/py/homekit/config/config.py
+++ b/include/py/homekit/config/config.py
@@ -3,6 +3,7 @@ import logging
import os
import cerberus
import cerberus.errors
+import re
from abc import ABC
from typing import Optional, Any, MutableMapping, Union
@@ -135,11 +136,25 @@ class ConfigUnit(BaseConfigUnit):
return None
@classmethod
- def _addr_schema(cls, required=False, only_ip=False, **kwargs):
+ def _addr_schema(cls, required=False, mac=False, only_ip=False, **kwargs):
+ def validate_mac_address(field, value, error):
+ if not re.match("[0-9a-fA-F]{2}([-:])[0-9a-fA-F]{2}(\\1[0-9a-fA-F]{2}){4}$", value):
+ error(field, "Invalid MAC address format")
+
+ if mac:
+ l_kwargs = {
+ 'type': 'string',
+ 'check_with': validate_mac_address
+ }
+ else:
+ l_kwargs = {
+ 'type': 'addr',
+ 'coerce': Addr.fromstring if not only_ip else Addr.fromipstring,
+ }
+
return {
- 'type': 'addr',
- 'coerce': Addr.fromstring if not only_ip else Addr.fromipstring,
'required': required,
+ **l_kwargs,
**kwargs
}