Skip to content

improve: Skip non-numeric weather forecast values - #672

Merged
edwardtfn merged 2 commits into
devfrom
improve/blueprint-numeric-guards
Nov 5, 2026
Merged

edwardtfn merged 2 commits into
devfrom
improve/blueprint-numeric-guards

Conversation

@panel-easy-assistant

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

Copy link
Copy Markdown
Contributor

Weather forecast values are now filtered with the is_number test before they are converted to numbers, instead of only rejecting none and empty strings. A forecast value that is not a number (for example unknown from a weather provider) is now skipped instead of stopping the automation with a template error, as in #671.

  • In the weather pages, 29 filter pairs rejectattr("x", "none") | rejectattr("x", "eq", "") become selectattr("x", "is_number"), for all numeric forecast values: temperature, templow, precipitation, precipitation_probability, wind_speed, humidity, pressure, uv_index, hours_of_sun and thunderstorm_probability. The selectattr("x", "defined") before them stays, as is_number fails on undefined values.
  • The other conversions to numbers in the Blueprint (float/int without a default) were reviewed and need no change: they are already guarded by is_number, have defaults, or work on values the Blueprint or Home Assistant formats itself (panel events, timestamps, timer durations, which Home Assistant always formats as H:MM:SS).

Checked locally by rendering the 11 changed templates in this version and in #671 with mocked forecasts (600 cases each): with valid data (missing, none, empty, numbers and numeric strings) the results are identical; with non-numeric values, this version renders while the previous one fails. Expanded size: -1,318 characters; template counts unchanged.

Builds on #671 (merge that first); merges cleanly with #669.

Summary by Sourcery

Prevent weather forecast automations from failing when providers return non-numeric forecast values.

Bug Fixes:

  • Skip non-numeric weather forecast values instead of failing template rendering during forecast processing.

Enhancements:

  • Apply consistent numeric filtering across weather forecast temperature, precipitation, wind, humidity, pressure, UV, sunshine, and thunderstorm data while preserving existing handling of missing values.

@sourcery-ai

sourcery-ai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Updates the weather forecast templates to select only defined numeric values before float/int conversion, preventing provider values such as unknown from aborting automation while preserving existing results for valid forecast data.

Flow diagram for numeric weather forecast filtering

flowchart LR
    A[Weather forecast values] --> B[selectattr defined]
    B --> C[selectattr is_number]
    C --> D[map float or int]
    D --> E[Render forecast]
    B --> F[Non-numeric value skipped]
Loading

File-Level Changes

Change Details Files
Filter forecast fields to numeric values before numeric conversion.
  • Replace none/empty-string rejection with selectattr(..., "is_number") while retaining defined-value guards.
  • Apply the filtering consistently to current forecast values and daily aggregations for all supported numeric weather fields.
  • Preserve existing fallback behavior when no valid numeric values remain.
nspanel_easy_blueprint.yaml
Validate that the filtering change preserves valid-data behavior and prevents template failures.
  • Compare rendering against the prior implementation using mocked forecasts covering missing, null, empty, numeric, numeric-string, and non-numeric values.
  • Confirm valid inputs produce identical results and non-numeric provider values are skipped rather than causing conversion errors.
nspanel_easy_blueprint.yaml

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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="nspanel_easy_blueprint.yaml" line_range="9932" />
<code_context>
                                         | selectattr("temperature", "defined")
-                                        | rejectattr("temperature", "none")
-                                        | rejectattr("temperature", "eq", "")
+                                        | selectattr("temperature", "is_number")
                                         | selectattr("datetime", "defined")
                                         | rejectattr("datetime", "none")
</code_context>
<issue_to_address>
**Old forecast values remain visible**

When a panel has displayed a numeric forecast value and the next forecast supplies a non-numeric value for that field while other fields remain numeric, the `is_number` filters exclude the affected field, and the weather-page sequence only writes available values (lines 10348–10359); it does not clear that field’s panel component. Other values update, but the component retains its previous forecast value, so the page shows mixed old and new data.

Clear each affected panel component when its forecast value is filtered out or otherwise unavailable.

Also at `nspanel_easy_blueprint.yaml:9941`, `nspanel_easy_blueprint.yaml:9951`, `nspanel_easy_blueprint.yaml:9961`, `nspanel_easy_blueprint.yaml:9970`, `nspanel_easy_blueprint.yaml:9979`, `nspanel_easy_blueprint.yaml:9989`, `nspanel_easy_blueprint.yaml:9998`, `nspanel_easy_blueprint.yaml:10030`, `nspanel_easy_blueprint.yaml:10034`, `nspanel_easy_blueprint.yaml:10039`, `nspanel_easy_blueprint.yaml:10047`, `nspanel_easy_blueprint.yaml:10053`, `nspanel_easy_blueprint.yaml:10124`, `nspanel_easy_blueprint.yaml:10130`, `nspanel_easy_blueprint.yaml:10145`, `nspanel_easy_blueprint.yaml:10154`, `nspanel_easy_blueprint.yaml:10160`, `nspanel_easy_blueprint.yaml:10169`, `nspanel_easy_blueprint.yaml:10175`, `nspanel_easy_blueprint.yaml:10184`, `nspanel_easy_blueprint.yaml:10193`, `nspanel_easy_blueprint.yaml:10204`, `nspanel_easy_blueprint.yaml:10213`, `nspanel_easy_blueprint.yaml:10224`, `nspanel_easy_blueprint.yaml:10232`, `nspanel_easy_blueprint.yaml:10243`, `nspanel_easy_blueprint.yaml:10252`.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: nspanel_easy_blueprint.yaml:9932


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

Comment thread nspanel_easy_blueprint.yaml Resolved
@edwardtfn
edwardtfn merged commit 92e6dae into dev Nov 5, 2026
22 checks passed
@edwardtfn
edwardtfn deleted the improve/blueprint-numeric-guards branch November 5, 2026 15:01
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