Skip to content

Latest commit

 

History

History
228 lines (178 loc) · 8.01 KB

File metadata and controls

228 lines (178 loc) · 8.01 KB

Fix Summary: Visualization and Hyperlinks from Notifications

Problem Statement

The issue reported: "AI summary is now great. visualisation and hyperlinks from notification still don't work" and "it has never opened to the webui"

Root Cause Analysis

We identified TWO separate problems:

Problem 1: Links Generated for Wrong Component Types

  • Issue: Notification links were being generated for ALL component types (addons, core, supervisor, OS updates)
  • Why it failed: The dependency graph only tracks integrations and HACS components, not addons or system components
  • Example failure: When user clicked link to "mosquitto" addon, the web UI couldn't find it because mosquitto addon is not in the integration dependency graph

Problem 2: URL Fragments Don't Work in Home Assistant Notifications (CRITICAL)

  • Issue: Links used URL fragments like /api/hassio_ingress/ha_sentry#whereused:component
  • Why it failed: Home Assistant's persistent notification system doesn't preserve URL fragments (the # part)
  • Result: Links would navigate to the base URL but the deep linking wouldn't trigger - the visualization would never show

The Solution

Fix 1: Only Generate Links for Tracked Components

Changed in: sentry_service.py (lines 691-699)

Before:

if self.config.enable_web_ui and component_name != 'Unknown':
    # Generate link for ALL components
    where_used_url = self._get_ingress_url() + f"#whereused:{component_domain}"
    notification_message += f"  [🔍 View Impact]({where_used_url})\n"

After:

if (self.config.enable_web_ui and 
    component_name != 'Unknown' and 
    component_type in ['integration', 'hacs']):  # Only for tracked types!
    where_used_url = self._get_ingress_url(mode="whereused", component=component_domain)
    notification_message += f"  [🔍 View Impact]({where_used_url})\n"

Result: Links are now only generated for integrations and HACS components, not for addons/core/supervisor/OS

Fix 2: Switch to Query Parameters Instead of URL Fragments

Changed in: sentry_service.py and web_server.py

Before:

URL format: /api/hassio_ingress/ha_sentry#whereused:mosquitto
Problem: Home Assistant strips the #whereused:mosquitto part

After:

URL format: /api/hassio_ingress/ha_sentry?mode=whereused&component=mosquitto
Solution: Query parameters are preserved in Home Assistant notifications!

Implementation:

  1. URL Generation (sentry_service.py):

    def _get_ingress_url(self, path: str = "", mode: str = "", component: str = "") -> str:
        base_url = f"/api/hassio_ingress/{self.ADDON_SLUG}"
        params = []
        if mode:
            params.append(f"mode={mode}")
        if component:
            params.append(f"component={quote(component)}")
        if params:
            base_url = f"{base_url}?{'&'.join(params)}"
        return base_url
  2. URL Parsing (web_server.py):

    function handleUrlFragment() {
        // Check for query parameters first (more reliable)
        const urlParams = new URLSearchParams(window.location.search);
        const mode = urlParams.get('mode');
        const component = urlParams.get('component');
        
        if (mode && component) {
            handleDeepLink(mode, component);
            return;
        }
        
        // Fallback to hash fragment for backward compatibility
        const hash = window.location.hash.substring(1);
        if (hash) {
            const [fragmentMode, value] = hash.split(':');
            handleDeepLink(fragmentMode, value);
        }
    }

Fix 3: Improved Error Messages

When a component is not found, users now see helpful messages:

  • "It's an add-on or system component (not tracked in dependency graph)"
  • "It's not installed on your system"
  • "The component name doesn't match the integration domain"
  • "Try selecting a component manually from the dropdown instead"

Fix 4: Enhanced Diagnostic Logging

Added logging at key points:

  • URL fragment/query parameter parsing
  • Component lookup success/failure
  • Deep link handling

Examples

Example 1: Integration Update Notification

Notification content:

🟡 **custom_integration (HACS Integration)**
Major update: 1.0.0 → 2.0.0
  [🔍 View Impact](/api/hassio_ingress/ha_sentry?mode=whereused&component=custom_integration)

What happens when clicked:

  1. Browser navigates to: /api/hassio_ingress/ha_sentry?mode=whereused&component=custom_integration
  2. Web UI parses query parameters: mode=whereused, component=custom_integration
  3. Switches to "Where Used" mode
  4. Selects custom_integration in dropdown
  5. Automatically triggers visualization
  6. User sees the dependency graph!

Example 2: Addon Update (No Link)

Notification content:

🟠 **mosquitto (Add-on)**
MQTT broker update: 2.0.15 → 2.0.18

No link generated because:

  • component_type = 'addon'
  • Addons are not in the dependency graph
  • Link would fail anyway, so we don't create it

Testing

Created comprehensive tests:

  1. test_notification_links.py - Validates URL generation and parsing
  2. test_notification_link_fix.py - Validates link generation logic

Test Results: All 21 test cases PASS ✅

Backward Compatibility

The web UI still supports the old URL fragment format for:

  • Direct browser bookmarks
  • Old notification links (if any exist)
  • Manual URL construction

Both formats work:

  • New: /api/hassio_ingress/ha_sentry?mode=whereused&component=test
  • Old: /api/hassio_ingress/ha_sentry#whereused:test

Impact

Before the Fix:

❌ Clicking notification links did nothing ❌ Links generated for addons that aren't tracked ❌ No way to jump directly to component analysis from notifications

After the Fix:

✅ Clicking notification links opens the WebUI with the correct visualization ✅ Links only generated for components that are actually tracked ✅ Deep linking works reliably from Home Assistant notifications ✅ Improved error messages when something isn't found ✅ Better diagnostic logging for troubleshooting

Files Modified

  1. ha_sentry/rootfs/app/sentry_service.py

    • Modified _get_ingress_url() to use query parameters
    • Updated link generation to filter by component type
    • Moved import to top of file
  2. ha_sentry/rootfs/app/web_server.py

    • Added URLSearchParams query parameter parsing
    • Created handleDeepLink() function
    • Added diagnostic logging
    • Improved error messages
  3. ha_sentry/CHANGELOG.md

    • Documented the changes
  4. tests/test_notification_links.py

    • Updated tests for query parameter format
  5. tests/test_notification_link_fix.py

    • Created comprehensive validation tests

Verification Checklist

✅ Links only generated for integration and HACS types ✅ URLs use query parameters instead of fragments ✅ Web UI parses query parameters correctly ✅ Web UI maintains backward compatibility with fragments ✅ Error messages are helpful and actionable ✅ All tests pass (21/21) ✅ Code review feedback addressed ✅ CHANGELOG updated

Next Steps for User

  1. Test the fix:

    • Wait for an update notification
    • Click the "View Impact" link
    • Verify it opens the WebUI with the visualization
  2. If it still doesn't work:

    • Check add-on logs for diagnostic messages
    • Look for lines starting with "handleDeepLink called"
    • Report the specific error message
  3. Alternative access:

    • You can always access the WebUI via:
      • "Sentry" panel in Home Assistant sidebar
      • Settings → Add-ons → Home Assistant Sentry → Open Web UI

Summary

The fix addresses the fundamental issue that notification links were using a URL format that Home Assistant doesn't support. By switching to query parameters, the links now work correctly and users can click directly from notifications to see component analysis in the WebUI.

The fix is minimal, surgical, and focused on solving the specific problem while maintaining backward compatibility and adding helpful diagnostics for future troubleshooting.