aboutsummaryrefslogtreecommitdiff
path: root/include/py/homekit/config/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'include/py/homekit/config/config.py')
-rw-r--r--include/py/homekit/config/config.py21
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
}