From c5e69cf2c9b89d546ad7a4f6bb26aef47021dd50 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sat, 17 Feb 2024 03:51:08 +0300 Subject: ipcam_ntp_util (wip: only supports hikvision cams for now) --- include/py/homekit/config/config.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'include/py/homekit/config/config.py') 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 } -- cgit v1.2.3