UniFi hostname bug handling: keep UniFi name in discovery listing for compatibility, but use device self-reported hostname for operations when bug detected.\n- get_tasmota_devices: detect bug and log self-reported hostname without overwriting listing fields.\n- process_single_device: prefer self-reported hostname for subsequent processing/logs.\n- get_device_details: on bug flag, use self-reported hostname (op_name) for MQTT/console/template updates so %hostname_base% derives from correct name.\n- Add informative logs showing override decisions.\nTargeted tests pass: unifi hostname bug fix/flag and device discovery.
This commit is contained in:
parent
8de801c324
commit
9646099a4f
@ -542,6 +542,7 @@ class TasmotaDiscovery:
|
|||||||
|
|
||||||
# Initialize the UniFi hostname bug flag
|
# Initialize the UniFi hostname bug flag
|
||||||
unifi_hostname_bug_detected = False
|
unifi_hostname_bug_detected = False
|
||||||
|
device_reported_hostname = None
|
||||||
|
|
||||||
# Check if device name or hostname matches unknown patterns
|
# Check if device name or hostname matches unknown patterns
|
||||||
unifi_name_matches_unknown = (
|
unifi_name_matches_unknown = (
|
||||||
@ -579,6 +580,10 @@ class TasmotaDiscovery:
|
|||||||
unifi_hostname_bug_detected = True
|
unifi_hostname_bug_detected = True
|
||||||
self.logger.info(f"UniFi OS hostname bug detected for {device_name}: self-reported hostname '{device_reported_hostname}' doesn't match unknown patterns")
|
self.logger.info(f"UniFi OS hostname bug detected for {device_name}: self-reported hostname '{device_reported_hostname}' doesn't match unknown patterns")
|
||||||
|
|
||||||
|
# If bug detected and we have the device-reported hostname, log it but keep UniFi fields for listing
|
||||||
|
if unifi_hostname_bug_detected and device_reported_hostname:
|
||||||
|
self.logger.info(f"UniFi bug detected: will prefer self-reported hostname '{device_reported_hostname}' during processing; keeping UniFi listing name '{device_name}'")
|
||||||
|
|
||||||
device_info = {
|
device_info = {
|
||||||
"name": device_name,
|
"name": device_name,
|
||||||
"ip": device_ip,
|
"ip": device_ip,
|
||||||
@ -1948,6 +1953,7 @@ class TasmotaDiscovery:
|
|||||||
# Check if device is in unknown_device_patterns
|
# Check if device is in unknown_device_patterns
|
||||||
unknown_patterns = target_network.get('unknown_device_patterns', [])
|
unknown_patterns = target_network.get('unknown_device_patterns', [])
|
||||||
is_unknown = False
|
is_unknown = False
|
||||||
|
device_reported_hostname = None
|
||||||
|
|
||||||
# Initialize variables for hostname bug detection
|
# Initialize variables for hostname bug detection
|
||||||
unifi_name_matches_unknown = False
|
unifi_name_matches_unknown = False
|
||||||
@ -2020,6 +2026,12 @@ class TasmotaDiscovery:
|
|||||||
unifi_hostname_bug_detected = (unifi_name_matches_unknown and not is_unknown and
|
unifi_hostname_bug_detected = (unifi_name_matches_unknown and not is_unknown and
|
||||||
not device_hostname_matches_unknown)
|
not device_hostname_matches_unknown)
|
||||||
|
|
||||||
|
# If bug detected and we have the device-reported hostname, prefer it going forward
|
||||||
|
if unifi_hostname_bug_detected and device_reported_hostname:
|
||||||
|
self.logger.info(f"Using device self-reported hostname '{device_reported_hostname}' instead of UniFi '{device_name}' for IP {device_ip}")
|
||||||
|
device_name = device_reported_hostname
|
||||||
|
device_hostname = device_reported_hostname
|
||||||
|
|
||||||
device_info = {
|
device_info = {
|
||||||
"name": device_name,
|
"name": device_name,
|
||||||
"ip": device_ip,
|
"ip": device_ip,
|
||||||
@ -2237,12 +2249,18 @@ class TasmotaDiscovery:
|
|||||||
url_mqtt = f"http://{ip}/cm?cmnd=Status%206"
|
url_mqtt = f"http://{ip}/cm?cmnd=Status%206"
|
||||||
response = requests.get(url_mqtt, timeout=5)
|
response = requests.get(url_mqtt, timeout=5)
|
||||||
mqtt_data = response.json()
|
mqtt_data = response.json()
|
||||||
|
|
||||||
|
# Decide the effective name to use for operations/logs
|
||||||
|
op_name = name
|
||||||
|
if device.get('unifi_hostname_bug_detected') and hostname_success and hostname:
|
||||||
|
op_name = hostname
|
||||||
|
self.logger.info(f"Using device self-reported hostname '{op_name}' for operations instead of UniFi name '{name}' (IP: {ip})")
|
||||||
|
|
||||||
# Check and update MQTT settings if needed
|
# Check and update MQTT settings if needed
|
||||||
mqtt_updated = check_mqtt_settings(ip, name, mqtt_data)
|
mqtt_updated = check_mqtt_settings(ip, op_name, mqtt_data)
|
||||||
|
|
||||||
# Check and update template (config_other) if needed
|
# Check and update template (config_other) if needed
|
||||||
template_updated = self.apply_config_other(ip, name)
|
template_updated = self.apply_config_other(ip, op_name)
|
||||||
|
|
||||||
# Console settings are now applied in configure_mqtt_settings
|
# Console settings are now applied in configure_mqtt_settings
|
||||||
console_updated = mqtt_updated
|
console_updated = mqtt_updated
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user