make new cleanDeviceName configurable, fix debug logging

This commit is contained in:
Ulrich Wisser
2024-04-24 18:02:33 +02:00
parent 788f23b955
commit 8bb9328201
2 changed files with 48 additions and 5 deletions

View File

@@ -605,6 +605,25 @@
"string": "The icon associated with the device. Check the <a href=\"https://github.com/jokob-sk/NetAlertX/blob/main/docs/ICONS.md\" target=\"_blank\">documentation on icons</a> for more details." "string": "The icon associated with the device. Check the <a href=\"https://github.com/jokob-sk/NetAlertX/blob/main/docs/ICONS.md\" target=\"_blank\">documentation on icons</a> for more details."
} }
] ]
},
{
"function": "dev_CleanDeviceName",
"type": "integer.checkbox",
"default_value": 0,
"options": [],
"localized": ["name", "description"],
"name": [
{
"language_code": "en_us",
"string": "Use new algorithm to cleanup device names"
}
],
"description": [
{
"language_code": "en_us",
"string": "Check to start using the new code for cleaning device names. Removes all labels starting with underscore and removes network domain and search list."
}
]
} }
], ],
"required": [ "required": [
@@ -627,10 +646,9 @@
"dev_Archived", "dev_Archived",
"dev_Network_Node_MAC_ADDR", "dev_Network_Node_MAC_ADDR",
"dev_Network_Node_port", "dev_Network_Node_port",
"dev_Icon" "dev_Icon",
"dev_CleanDeviceName"
], ],
"additionalProperties": false "additionalProperties": false
} }

View File

@@ -573,8 +573,33 @@ def resolve_device_name_pholus (pMAC, pIP, allRes, nameNotFound, match_IP = Fals
import dns.resolver import dns.resolver
def cleanDeviceName(str, match_IP): def cleanDeviceName(str, match_IP):
if get_setting_value('NEWDEV_dev_CleanDeviceName'):
return NEW_cleanDeviceName(str, match_IP)
print("START cleanDeviceName(" + str + ")") # alternative str.split('.')[0]
str = str.replace("._airplay", "")
str = str.replace("._tcp", "")
str = str.replace(".localdomain", "")
str = str.replace(".local", "")
str = str.replace("._esphomelib", "")
str = str.replace("._googlecast", "")
str = str.replace(".lan", "")
str = str.replace(".home", "")
str = re.sub(r'-[a-fA-F0-9]{32}', '', str) # removing last part of e.g. Nest-Audio-ff77ff77ff77ff77ff77ff77ff77ff77
str = re.sub(r'#.*', '', str) # Remove everything after '#' including the '#'
# remove trailing dots
if str.endswith('.'):
str = str[:-1]
if match_IP:
str = str + " (IP match)"
return str
def NEW_cleanDeviceName(str, match_IP):
mylog('debug', ["START cleanDeviceName(" + str + ")"])
# replace all labels starting with underscore # replace all labels starting with underscore
str = re.sub(r'^_[^\.]*\.', '', str) # leading label str = re.sub(r'^_[^\.]*\.', '', str) # leading label
@@ -604,7 +629,7 @@ def cleanDeviceName(str, match_IP):
if match_IP: if match_IP:
str = str + " (IP match)" str = str + " (IP match)"
print("END cleanDeviceName = " + str) mylog('debug', ["END cleanDeviceName = " + str])
# done # done
return str return str