1919MAC_ADDRESS_MASK_REGEX = re .compile (r"^(00:){4}[0-9a-fA-F]{2}[:-][0-9a-fA-F]{2}$" )
2020
2121
22+ # Helper functions
2223def is_mac_address (value : str ) -> bool :
2324 """Check if a string is a valid MAC address."""
2425 return bool (MAC_ADDRESS_REGEX .match (value ))
@@ -38,27 +39,6 @@ def is_ip_address(value: str) -> bool:
3839 return False
3940
4041
41- def _check_and_log_unknown_enum_value (
42- data_dict : dict [str , Any ],
43- key : str ,
44- enum_class : type [Enum ],
45- dataclass_name : str ,
46- field_name : str ,
47- ) -> None :
48- """Clean unsupported parameters with logging."""
49- value = data_dict .get (key )
50- if value is not None and isinstance (value , str ):
51- if value not in [e .value for e in enum_class ]:
52- logger .warning (
53- "Unknown value '%s' for %s.%s. Please report at "
54- "https://github.com/CoMPaTech/python-airos/issues so we can add support." ,
55- value ,
56- dataclass_name ,
57- field_name ,
58- )
59- del data_dict [key ]
60-
61-
6242def redact_data_smart (data : dict ) -> dict :
6343 """Recursively redacts sensitive keys in a dictionary."""
6444 sensitive_keys = {
@@ -85,7 +65,7 @@ def _redact(d: dict):
8565 if k in sensitive_keys :
8666 if isinstance (v , str ) and (is_mac_address (v ) or is_mac_address_mask (v )):
8767 # Redact only the first 6 hex characters of a MAC address
88- redacted_d [k ] = "00:00:00:00 :" + v .replace ("-" , ":" ).upper ()[- 5 :]
68+ redacted_d [k ] = "00:11:22:33 :" + v .replace ("-" , ":" ).upper ()[- 5 :]
8969 elif isinstance (v , str ) and is_ip_address (v ):
9070 # Redact to a dummy local IP address
9171 redacted_d [k ] = "127.0.0.3"
@@ -109,46 +89,28 @@ def _redact(d: dict):
10989 return _redact (data )
11090
11191
112- def _redact_ip_addresses (addresses : str | list [str ]) -> str | list [str ]:
113- """Redacts the first three octets of an IPv4 address."""
114- if isinstance (addresses , str ):
115- addresses = [addresses ]
92+ # Data class start
11693
117- redacted_list = []
118- for ip in addresses :
119- try :
120- parts = ip .split ("." )
121- if len (parts ) == 4 :
122- # Keep the last octet, but replace the rest with a placeholder.
123- redacted_list .append (f"127.0.0.{ parts [3 ]} " )
124- else :
125- # Handle non-standard IPs or IPv6 if it shows up here
126- redacted_list .append ("REDACTED" )
127- except (IndexError , ValueError ):
128- # In case the IP string is malformed
129- redacted_list .append ("REDACTED" )
130-
131- return redacted_list if isinstance (addresses , list ) else redacted_list [0 ]
132-
133-
134- def _redact_mac_addresses (macs : str | list [str ]) -> str | list [str ]:
135- """Redacts the first four octets of a MAC address."""
136- if isinstance (macs , str ):
137- macs = [macs ]
138-
139- redacted_list = []
140- for mac in macs :
141- try :
142- parts = mac .split (":" )
143- if len (parts ) == 6 :
144- # Keep the last two octets, replace the rest with a placeholder
145- redacted_list .append (f"00:11:22:33:{ parts [4 ]} :{ parts [5 ]} " )
146- else :
147- redacted_list .append ("REDACTED" )
148- except (IndexError , ValueError ):
149- redacted_list .append ("REDACTED" )
15094
151- return redacted_list if isinstance (macs , list ) else redacted_list [0 ]
95+ def _check_and_log_unknown_enum_value (
96+ data_dict : dict [str , Any ],
97+ key : str ,
98+ enum_class : type [Enum ],
99+ dataclass_name : str ,
100+ field_name : str ,
101+ ) -> None :
102+ """Clean unsupported parameters with logging."""
103+ value = data_dict .get (key )
104+ if value is not None and isinstance (value , str ):
105+ if value not in [e .value for e in enum_class ]:
106+ logger .warning (
107+ "Unknown value '%s' for %s.%s. Please report at "
108+ "https://github.com/CoMPaTech/python-airos/issues so we can add support." ,
109+ value ,
110+ dataclass_name ,
111+ field_name ,
112+ )
113+ del data_dict [key ]
152114
153115
154116class IeeeMode (Enum ):
@@ -328,8 +290,8 @@ class EthList:
328290class GPSData :
329291 """Leaf definition."""
330292
331- lat : str | None = None
332- lon : str | None = None
293+ lat : float | None = None
294+ lon : float | None = None
333295 fix : int | None = None
334296 sats : int | None = None # LiteAP GPS
335297 dim : int | None = None # LiteAP GPS
0 commit comments