TasmotaManager/template_no_match_summary.md

3.1 KiB

Template No Match Tracking and Reporting

Issue Description

When the check_and_update_template method couldn't find a match for either the Device Name or Template in the mqtt.config_other configuration, it would silently continue without providing any information about what was set on the device. This made it difficult for users to understand why a template wasn't applied and what the current device configuration was.

Changes Made

The check_and_update_template method has been enhanced to track and report detailed information when no match is found. Specifically:

  1. Changed the log level from DEBUG to INFO for better visibility in logs
  2. Added more detailed log messages that include:
    • A clear message that no matches were found
    • The current Device Name on the device
    • The current Template on the device
  3. Added user-friendly console output using print() statements that:
    • Clearly indicates no template match was found
    • Shows the device name and IP address
    • Displays the current Device Name on the device
    • Displays the current Template on the device
    • Provides a suggestion to add an appropriate entry to the configuration file

Code Changes

The following changes were made to the check_and_update_template method:

# Before
else:
    self.logger.debug(f"{name}: No matches found in config_other for device name or template")

# After
else:
    # No matches found, print detailed information about what's on the device
    self.logger.info(f"{name}: No matches found in config_other for either Device Name or Template")
    self.logger.info(f"{name}: Current Device Name on device: '{device_name}'")
    self.logger.info(f"{name}: Current Template on device: '{current_template}'")
    print(f"\nNo template match found for device {name} at {ip}")
    print(f"  Device Name on device: '{device_name}'")
    print(f"  Template on device: '{current_template}'")
    print("Please add an appropriate entry to mqtt.config_other in your configuration file.")

Testing

A test script test_template_no_match.py was created to verify the changes. The script:

  1. Gets a test device from current.json
  2. Temporarily modifies the mqtt.config_other section to ensure no match will be found
  3. Calls the check_and_update_template method
  4. Verifies that appropriate messages are printed

The test confirmed that the method now correctly tracks and reports detailed information when no match is found.

Benefits

These changes provide several benefits:

  1. Better Visibility: Users can now see when a template match is not found, rather than the process silently continuing.
  2. Detailed Information: The current Device Name and Template on the device are clearly displayed, making it easier to understand the current configuration.
  3. Actionable Guidance: The message suggests adding an appropriate entry to the configuration file, guiding users on how to resolve the issue.

This enhancement improves the user experience by providing clear, actionable information when a template match is not found, helping users understand and resolve configuration issues more easily.