Skip to content

Conversation

@depoll
Copy link
Contributor

@depoll depoll commented Aug 5, 2025

Breaking change

Proposed change

Fixes an issue with as_function that prevented it from working with 0-argument functions.

Type of change

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

Additional information

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

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

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

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings August 5, 2025 17:14
@depoll depoll requested a review from a team as a code owner August 5, 2025 17:14
@home-assistant home-assistant bot added bugfix cla-signed core small-pr PRs with less than 30 lines. labels Aug 5, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug in the as_function helper that prevented it from working with zero-argument functions. The issue was that the wrapper function incorrectly expected a required value parameter, making it impossible to call macros that don't need any arguments.

  • Removes the required value parameter from the as_function wrapper
  • Updates the macro call to not pass the removed value parameter
  • Adds test coverage for zero-argument function scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
homeassistant/helpers/template.py Fixes the as_function wrapper to support zero-argument functions by removing the required value parameter
tests/helpers/test_template.py Adds test case to verify as_function works correctly with zero-argument macros
Comments suppressed due to low confidence (1)

tests/helpers/test_template.py:853

  • [nitpick] The macro name macro_get_hello is redundant since it's already a macro. Consider renaming to just get_hello for clarity.
            {%- macro macro_get_hello(returns) -%}

@depoll depoll changed the title as_function doesn't work for zero-argument functions Fix zero-argument functions with as_function Aug 5, 2025
Copy link
Member

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Thanks @depoll 👍

@edenhaus
Copy link
Member

edenhaus commented Aug 6, 2025

test failure unrelated

@edenhaus edenhaus merged commit 2215777 into home-assistant:dev Aug 6, 2025
43 of 44 checks passed
@edenhaus edenhaus added this to the 2025.8.0 milestone Aug 6, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants