Skip to content

Conversation

@balloob
Copy link
Member

@balloob balloob commented Nov 28, 2025

Breaking change

Proposed change

This adds an API for add-ons served via Ingress similar to how we offer one for custom panels inside their iframe.

Add-ons can do the following things:

// Subscribe to layout changes
const unsubscribe = window.parent.hassIngress.subscribe(({ narrow, route }) => {
  if (narrow) {
    showMobileLayout();
    showMenuButton(); // Add-on renders its own menu button
  } else {
    showDesktopLayout();
  }
  
  console.log('Current path:', route.path);
}, {
  // optional options
  hideToolbar: true
});

// Navigate to a page
window.parent.hassIngress.navigate('/lovelace/dashboard');

// Show sidebar of Home Assistant (for in narrow mode)
window.parent.hassIngress.toggleMenu();

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:


Note

Adds window.hassIngress API (navigate, toggleMenu, subscribe) and optional toolbar hiding for ingress add-ons, with lifecycle integration and reactive updates.

  • Ingress add-on API:
    • Expose window.hassIngress with:
      • navigate(path, options?), toggleMenu()
      • Reactive narrow and route properties
      • subscribe(({ narrow, route }, { hideToolbar? }) => unsubscribe) with immediate emit and unsubscribe handling
    • Keep API in sync on narrow/route changes and clean up on disconnect
  • UI behavior:
    • Header/menu button hidden when (narrow || sidebar always_hidden) and add-on sets hideToolbar=true; add-ons can render their own menu button
  • Internals:
    • Add _hideToolbar and _propertyCallback state, setup/cleanup helpers for API lifecycle
    • Minor imports and type additions (NavigateOptions)

Written by Cursor Bugbot for commit e72d326. This will update automatically on new commits. Configure here.

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @claude

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant bot marked this pull request as draft November 28, 2025 13:19
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@github-actions github-actions bot added the Supervisor Related to the supervisor panel label Nov 28, 2025
@balloob balloob force-pushed the claude/expose-panel-code-ingress-01GR63DfVQBgayfBKXgL9bp7 branch from 8ae205c to e72d326 Compare November 28, 2025 13:21
@balloob balloob marked this pull request as ready for review November 28, 2025 13:26
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

}, 60000);

this._addon = addon;
this._setupHassIngress();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Stale state persists when switching between add-ons

When switching between add-ons, _setupHassIngress is called without first cleaning up the previous state. The _propertyCallback and _hideToolbar values from the old add-on persist because _cleanupHassIngress() is only called in disconnectedCallback(). This causes the previous add-on's hideToolbar setting to incorrectly affect the new add-on's toolbar visibility, and the old callback may still be invoked in updated() when properties change.

Additional Locations (1)

Fix in Cursor Fix in Web

@balloob balloob marked this pull request as draft November 28, 2025 14:33
@balloob
Copy link
Member Author

balloob commented Nov 28, 2025

Marked as draft as I want to add the feature to #28214

Implements secure communication between Home Assistant and ingress
add-ons using postMessage instead of direct window access.

Changes to ingress-view:
- Added postMessage listener to handle messages from iframe
- Added sandbox attribute to iframe for improved security
- Support for subscribe/unsubscribe, navigate, and toggleMenu
- Automatically sends property updates (narrow/route) to subscribed add-ons
- hideToolbar option to let add-ons manage their own toolbar

New client library (hass-app-integrate.js):
- Standalone JavaScript library for add-on developers
- Simple API: subscribe(), navigate(), toggleMenu()
- Handles all postMessage communication automatically
- Can be included via <script> tag in add-on UIs

Example usage:
  const hassApp = new HassAppIntegrate();
  hassApp.subscribe(({ narrow, route }) => {
    // Handle layout changes
  }, { hideToolbar: true });
  hassApp.navigate('/lovelace/dashboard');
  hassApp.toggleMenu();
@balloob balloob force-pushed the claude/expose-panel-code-ingress-01GR63DfVQBgayfBKXgL9bp7 branch from e72d326 to fe912d7 Compare November 28, 2025 15:40
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @claude

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-needed cla-signed Supervisor Related to the supervisor panel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants