Skip to content

improve: Build the API subscriptions list in a single template - #675

Merged
edwardtfn merged 2 commits into
devfrom
improve/blueprint-api-subscriptions-single-template
Nov 5, 2026
Merged

edwardtfn merged 2 commits into
devfrom
improve/blueprint-api-subscriptions-single-template

Conversation

@panel-easy-assistant

@panel-easy-assistant panel-easy-assistant Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Builds the list of API subscriptions (home page chips, weather picture, outdoor and indoor temperature, custom buttons, wake-up sensors and the temperature calibration reference) in a single template.

  • subs_lists and api_subs_mapping are replaced by subs_chips (the chip inputs, no templates) and one api_subscriptions template that builds the whole list. The per-item comments are kept as Jinja comments.
  • The list sent to the panel is unchanged: same items, same order, same fields.

Distinct templates go from 1,013 to 1,003 (-10), widening the margin under Home Assistant's template cache of 1,024 entries, which Spook depends on. The expanded size grows slightly (+171 characters, the indentation inside the template); the file shrinks by 880 bytes.

A new equivalence test, .github/scripts/test_api_subscriptions.py, renders the variables of both versions with mocked inputs and state (weather, outdoor and indoor temperature as empty, single entity or list, visible or not; calibration reference as empty, sensor, climate or the panel's own entities, with and without the embedded thermostat; wake-up sensors with gaps; chips and custom buttons with missing, empty, invalid and valid entities) and compares the resulting subscription list. Result against dev: 4,000 cases, 0 differences. Deliberate mutations (component, attribute, page, sensor numbering) are all detected.

Related to #657 and #636.

Summary by Sourcery

Consolidate API subscription construction into one template without changing the subscriptions sent to the panel.

Enhancements:

  • Consolidate API subscription generation into a single template while preserving the existing subscription list and ordering.
  • Reduce the number of Home Assistant templates to leave more capacity under the template cache limit.

Tests:

  • Add a seeded equivalence test covering 4,000 mocked input and state combinations to verify that API subscriptions remain unchanged across refactorings.

@sourcery-ai

sourcery-ai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Refactors API subscription generation from multiple intermediate templates into a single consolidated Jinja template, preserving the panel’s list and ordering while reducing the Home Assistant template-cache footprint. Adds a seeded 4,000-case equivalence test with mocked inputs and state to detect behavioral changes.

Sequence diagram for API subscription list rendering

sequenceDiagram
    participant A as Panel automation
    participant J as api_subscriptions
    participant H as Home Assistant state
    participant P as Panel
    A->>J: Render subscription template
    J->>H: Read entity and thermostat state
    H-->>J: Weather, temperature, calibration, and wake-up values
    J->>J: Combine chips, weather, buttons, wake-up, and calibration
    J->>J: Filter undefined and empty entities
    J-->>A: Ordered subscription list
    A->>P: Send API subscriptions
Loading

Flow diagram for consolidated API subscription generation

flowchart LR
    I["Blueprint inputs and entity state"] --> C["subs_chips"]
    I --> T["api_subscriptions template"]
    C --> T
    T --> W["Weather and temperatures"]
    T --> K["Custom buttons"]
    T --> U["Wake-up sensors"]
    T --> R["Calibration reference"]
    W --> F["Filter valid subscriptions"]
    K --> F
    U --> F
    R --> F
    F --> P["Panel API subscription list"]
Loading

File-Level Changes

Change Details Files
Consolidate API subscription construction into one Jinja template while preserving the existing subscription output.
  • Replace the intermediate subscription mapping with input-only chip data and a single template for weather, temperature, calibration, custom-button, wake-up, and chip subscriptions.
  • Generate wake-up sensor entries, weather/temperature entries, and calibration entries directly in the consolidated template, retaining ordering, fields, filtering, and conditional behavior.
  • Keep per-item documentation as Jinja comments and reduce template count by ten, with a small increase in blueprint content from indentation/template expansion.
nspanel_easy_blueprint.yaml
Add a deterministic equivalence test covering the refactoring against a reference blueprint.
  • Load and render both blueprint versions with mocked Home Assistant state and resolved blueprint inputs.
  • Exercise 4,000 seeded combinations covering entity shapes, visibility, invalid or missing inputs, calibration modes, thermostat state, wake-up gaps, chips, and custom buttons.
  • Compare the complete ordered subscription records and report differences, including rendering errors; document usage and dependencies.
.github/scripts/test_api_subscriptions.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@edwardtfn
edwardtfn merged commit 79cf377 into dev Nov 5, 2026
54 checks passed
@edwardtfn
edwardtfn deleted the improve/blueprint-api-subscriptions-single-template branch November 5, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant