NEWDEV_LESS_NAME_CLEANUP + Internet ParentNode fix + 📚Docs

This commit is contained in:
jokob-sk
2024-07-16 20:27:15 +10:00
parent f502d93854
commit b45e82b2a0
7 changed files with 40 additions and 84 deletions

View File

@@ -223,18 +223,32 @@ def create_new_devices (db):
)
SELECT
cur_MAC,
CASE WHEN LENGTH(TRIM(cur_Name)) > 0 THEN cur_Name ELSE '(unknown)' END,
CASE
WHEN LENGTH(TRIM(cur_Name)) > 0 THEN cur_Name ELSE '(unknown)'
END,
cur_Vendor,
cur_IP,
?,
?,
cur_SyncHubNodeName,
{sql_generateGuid},
CASE WHEN LENGTH(TRIM(cur_NetworkNodeMAC)) > 0 THEN cur_NetworkNodeMAC ELSE '{get_setting_value('NEWDEV_dev_Network_Node_MAC_ADDR')}' END,
CASE
WHEN LENGTH(TRIM(cur_NetworkNodeMAC)) > 0
AND cur_MAC != 'Internet'
THEN cur_NetworkNodeMAC
ELSE
CASE
WHEN cur_MAC = 'Internet'
THEN 'null'
ELSE '{get_setting_value('NEWDEV_dev_Network_Node_MAC_ADDR')}'
END
END,
cur_PORT,
cur_NetworkSite,
cur_SSID,
CASE WHEN LENGTH(TRIM(cur_Type)) > 0 THEN cur_Type ELSE '{get_setting_value('NEWDEV_dev_DeviceType')}' END,
CASE
WHEN LENGTH(TRIM(cur_Type)) > 0 THEN cur_Type ELSE '{get_setting_value('NEWDEV_dev_DeviceType')}'
END,
{newDevDefaults}
FROM CurrentScan
WHERE 1=1

View File

@@ -727,38 +727,6 @@ def cleanDeviceName(str, match_IP):
# add matching info
if match_IP:
str = str + " (IP match)"
if get_setting_value('NEWDEV_LESS_NAME_CLEANUP'):
mylog('debug', ["[Name cleanup] Using new cleanDeviceName(" + str + ")"])
# replace all labels starting with underscore
str = re.sub(r'^_[^\.]*\.', '', str) # leading label
str = re.sub(r'\._[^\.]*\.', '.', str) # nested label
# get a stub resolver for access to resolv.conf configuration
resolv = dns.resolver.Resolver()
# replace the local domain name
str = re.sub(r'\.' + resolv.domain.to_text() + r'$', '', str)
# replace dns search list
for name in resolv.search:
str = re.sub(r'\.' + name.to_text() + r'$', '', str)
# removing last part of e.g. Nest-Audio-ff77ff77ff77ff77ff77ff77ff77ff77
str = re.sub(r'-[a-fA-F0-9]{32}', '', str)
# Remove everything after '#' including the '#'
str = re.sub(r'#.*', '', str)
# remove trailing dot
if str.endswith('.'):
str = str[:-1]
# done
mylog('debug', ["[Name cleanup] cleanDeviceName = " + str])
return str
# Applying cleanup REGEXEs
mylog('debug', ["[Name cleanup] Using old cleanDeviceName(" + str + ")"])
@@ -766,10 +734,10 @@ def cleanDeviceName(str, match_IP):
regexes = get_setting_value('NEWDEV_NAME_CLEANUP_REGEX')
for rgx in regexes:
mylog('debug', ["[cleanDeviceName] applying regex : " + rgx])
mylog('debug', ["[cleanDeviceName] name before regex : " + str])
mylog('trace', ["[cleanDeviceName] applying regex : " + rgx])
mylog('trace', ["[cleanDeviceName] name before regex : " + str])
str = re.sub(rgx, "", str)
mylog('debug', ["[cleanDeviceName] name after regex : " + str])
mylog('trace', ["[cleanDeviceName] name after regex : " + str])
str = re.sub(r'\.\b', '', str) # trailing dot after words
str = re.sub(r'\.$', '', str) # trailing dot at the end of the string