make new cleanDeviceName configurable, fix debug logging
This commit is contained in:
@@ -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."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"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": [
|
||||
@@ -627,10 +646,9 @@
|
||||
"dev_Archived",
|
||||
"dev_Network_Node_MAC_ADDR",
|
||||
"dev_Network_Node_port",
|
||||
"dev_Icon"
|
||||
"dev_Icon",
|
||||
"dev_CleanDeviceName"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -573,8 +573,33 @@ def resolve_device_name_pholus (pMAC, pIP, allRes, nameNotFound, match_IP = Fals
|
||||
import dns.resolver
|
||||
|
||||
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
|
||||
str = re.sub(r'^_[^\.]*\.', '', str) # leading label
|
||||
@@ -604,7 +629,7 @@ def cleanDeviceName(str, match_IP):
|
||||
if match_IP:
|
||||
str = str + " (IP match)"
|
||||
|
||||
print("END cleanDeviceName = " + str)
|
||||
mylog('debug', ["END cleanDeviceName = " + str])
|
||||
|
||||
# done
|
||||
return str
|
||||
|
||||
Reference in New Issue
Block a user