Unifi hostname bug: use self-reported hostname base (before '-') for unknown pattern comparison in bug detection across is_hostname_unknown, get_tasmota_devices, and process_single_device. Add exception handling in is_hostname_unknown for request failures. All targeted tests pass.
This commit is contained in:
parent
c31bcbdf85
commit
8de801c324
@ -382,15 +382,21 @@ class TasmotaDiscovery:
|
|||||||
self.logger.debug(f"Handling hostname '{hostname}' from Unifi OS (bug handling enabled)")
|
self.logger.debug(f"Handling hostname '{hostname}' from Unifi OS (bug handling enabled)")
|
||||||
|
|
||||||
# Get the device's self-reported hostname using the common function
|
# Get the device's self-reported hostname using the common function
|
||||||
|
try:
|
||||||
device_reported_hostname, success = self.get_device_hostname(ip, hostname, timeout=5, log_level='debug')
|
device_reported_hostname, success = self.get_device_hostname(ip, hostname, timeout=5, log_level='debug')
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.debug(f"Failed to retrieve self-reported hostname for {hostname} at {ip}: {e}")
|
||||||
|
device_reported_hostname, success = "", False
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
# Check if the self-reported hostname also matches unknown patterns
|
# Check if the self-reported hostname also matches unknown patterns
|
||||||
device_hostname_matches_unknown = False
|
device_hostname_matches_unknown = False
|
||||||
|
# Use the base of the self-reported hostname up to the first '-' for bug detection
|
||||||
|
device_hostname_base = device_reported_hostname.split('-')[0].lower()
|
||||||
for pattern in patterns:
|
for pattern in patterns:
|
||||||
if self._match_pattern(device_reported_hostname.lower(), pattern, match_entire_string=False):
|
if self._match_pattern(device_hostname_base, pattern, match_entire_string=False):
|
||||||
device_hostname_matches_unknown = True
|
device_hostname_matches_unknown = True
|
||||||
self.logger.debug(f"Device's self-reported hostname '{device_reported_hostname}' matches unknown pattern: {pattern}")
|
self.logger.debug(f"Device's self-reported hostname base '{device_hostname_base}' (from '{device_reported_hostname}') matches unknown pattern: {pattern}")
|
||||||
break
|
break
|
||||||
|
|
||||||
# If UniFi name matches unknown patterns but device's self-reported name doesn't,
|
# If UniFi name matches unknown patterns but device's self-reported name doesn't,
|
||||||
@ -559,10 +565,12 @@ class TasmotaDiscovery:
|
|||||||
if success:
|
if success:
|
||||||
# Check if the self-reported hostname also matches unknown patterns
|
# Check if the self-reported hostname also matches unknown patterns
|
||||||
device_hostname_matches_unknown = False
|
device_hostname_matches_unknown = False
|
||||||
|
# Use the base of the self-reported hostname up to the first '-' for bug detection
|
||||||
|
device_hostname_base = device_reported_hostname.split('-')[0].lower()
|
||||||
for pattern in unknown_patterns:
|
for pattern in unknown_patterns:
|
||||||
if self._match_pattern(device_reported_hostname.lower(), pattern, match_entire_string=False):
|
if self._match_pattern(device_hostname_base, pattern, match_entire_string=False):
|
||||||
device_hostname_matches_unknown = True
|
device_hostname_matches_unknown = True
|
||||||
self.logger.debug(f"Device's self-reported hostname '{device_reported_hostname}' matches unknown pattern: {pattern}")
|
self.logger.debug(f"Device's self-reported hostname base '{device_hostname_base}' (from '{device_reported_hostname}') matches unknown pattern: {pattern}")
|
||||||
break
|
break
|
||||||
|
|
||||||
# If UniFi name matches unknown patterns but device's self-reported name doesn't,
|
# If UniFi name matches unknown patterns but device's self-reported name doesn't,
|
||||||
@ -1974,10 +1982,12 @@ class TasmotaDiscovery:
|
|||||||
if success and device_reported_hostname:
|
if success and device_reported_hostname:
|
||||||
# Check if the self-reported hostname also matches unknown patterns
|
# Check if the self-reported hostname also matches unknown patterns
|
||||||
device_hostname_matches_unknown = False
|
device_hostname_matches_unknown = False
|
||||||
|
# Use the base of the self-reported hostname up to the first '-' for bug detection
|
||||||
|
device_hostname_base = device_reported_hostname.split('-')[0].lower()
|
||||||
for pattern in unknown_patterns:
|
for pattern in unknown_patterns:
|
||||||
if self._match_pattern(device_reported_hostname.lower(), pattern, match_entire_string=False):
|
if self._match_pattern(device_hostname_base, pattern, match_entire_string=False):
|
||||||
device_hostname_matches_unknown = True
|
device_hostname_matches_unknown = True
|
||||||
self.logger.info(f"Device's self-reported hostname '{device_reported_hostname}' matches unknown pattern: {pattern}")
|
self.logger.info(f"Device's self-reported hostname base '{device_hostname_base}' (from '{device_reported_hostname}') matches unknown pattern: {pattern}")
|
||||||
break
|
break
|
||||||
|
|
||||||
# Only declare as unknown if both UniFi-reported and self-reported hostnames match unknown patterns
|
# Only declare as unknown if both UniFi-reported and self-reported hostnames match unknown patterns
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user