diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2024-02-17 03:51:08 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2024-02-17 03:51:08 +0300 |
commit | c5e69cf2c9b89d546ad7a4f6bb26aef47021dd50 (patch) | |
tree | 61ea0185392909cf9d0198c51f439a2ee01e8089 /include/py/homekit/config/config.py | |
parent | 0ce2e41a2bad790c5232fafb4b6ed631ca8cd957 (diff) |
ipcam_ntp_util (wip: only supports hikvision cams for now)
Diffstat (limited to 'include/py/homekit/config/config.py')
-rw-r--r-- | include/py/homekit/config/config.py | 21 |
1 files changed, 18 insertions, 3 deletions
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 } |