cleanDeviceName rewritten to remove all _ labels and remove search list and local domain
This commit is contained in:
@@ -570,26 +570,43 @@ def resolve_device_name_pholus (pMAC, pIP, allRes, nameNotFound, match_IP = Fals
|
|||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
import dns.resolver
|
||||||
|
|
||||||
def cleanDeviceName(str, match_IP):
|
def cleanDeviceName(str, match_IP):
|
||||||
# alternative str.split('.')[0]
|
|
||||||
str = str.replace("._airplay", "")
|
print("START cleanDeviceName(" + str + ")")
|
||||||
str = str.replace("._tcp", "")
|
|
||||||
str = str.replace(".localdomain", "")
|
# replace all labels starting with underscore
|
||||||
str = str.replace(".local", "")
|
str = re.sub(r'^_[^\.]*\.', '', str) # leading label
|
||||||
str = str.replace("._esphomelib", "")
|
str = re.sub(r'\._[^\.]*\.', '.', str) # nested label
|
||||||
str = str.replace("._googlecast", "")
|
|
||||||
str = str.replace(".lan", "")
|
# get a stub resolver for access to resolv.conf configuration
|
||||||
str = str.replace(".home", "")
|
resolv = dns.resolver.Resolver()
|
||||||
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 '#'
|
# replace the local domain name
|
||||||
# remove trailing dots
|
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('.'):
|
if str.endswith('.'):
|
||||||
str = str[:-1]
|
str = str[:-1]
|
||||||
|
|
||||||
|
# add matching info
|
||||||
if match_IP:
|
if match_IP:
|
||||||
str = str + " (IP match)"
|
str = str + " (IP match)"
|
||||||
|
|
||||||
|
print("END cleanDeviceName = " + str)
|
||||||
|
|
||||||
|
# done
|
||||||
return str
|
return str
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user