Skip to content

Conversation

@mitchellwrosen
Copy link

@mitchellwrosen mitchellwrosen commented Jan 31, 2026

Breaking change

What breaks
Explicitly configuring a legacy notifier to send a message with title: '' will no longer fall back on the default title of "Home Assistant"

How to make it work again
Delete title: '' entirely, or replace with title: Home Assistant

Why we did this
To allow empty string titles

Proposed change

I propose we tweak the logic that parses notification configuration and calls legacy notification services to explicitly allow empty titles. My motivation is integrating Home Assistant with https://github.com/caronc/apprise. In Apprise, notification titles are optional. For certain backends (like Discord), messages without titles look a lot better, as they can be shorter and don't have a superfluous newline.

I dug around in Git history a bit, and found the original intent was to allow None titles (i.e. missing title key in yaml configuration): #3100

This was followed up by some hotfix patch that introduced the current logic (almost 10 years ago!), which I believe accidentally conflates None with "" by using the truthiness of strings, rather than comparing to None directly: #3302

In this PR, I've just swapped the truthiness check for a direct comparison to None, exactly as we do a few lines below for ATTR_TARGET.

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

  • I understand the code I am submitting and can explain how it works.
  • 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.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

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 diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings January 31, 2026 17:52
@mitchellwrosen mitchellwrosen requested a review from a team as a code owner January 31, 2026 17:52
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 @mitchellwrosen

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
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.

@home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (notify) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of notify can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign notify Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.
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 adjusts the legacy notify service so that explicitly configured empty-string titles are forwarded as-is instead of being treated as missing and replaced with the default "Home Assistant", and adds regression tests to cover this behavior.

Changes:

  • Updates the legacy notify service’s _async_notify_message_service to treat ATTR_TITLE as present whenever it is not None, allowing empty strings instead of relying on truthiness.
  • Adds a YAML-script-based test to verify that an explicitly empty title (title: '') is forwarded unchanged through the legacy notify path.

Reviewed changes

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

File Description
homeassistant/components/notify/legacy.py Adjusts ATTR_TITLE handling in _async_notify_message_service to check is not None and always forward explicitly provided titles, including empty strings.
tests/components/notify/test_legacy.py Adds a new test ensuring that a script-driven notify call with title: '' forwards an empty title instead of falling back to the default.
Comment on lines +245 to +246
if service.data.get(ATTR_TITLE) is not None:
kwargs[ATTR_TITLE] = service.data.get(ATTR_TITLE)
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The new ATTR_TITLE handling now calls service.data.get(ATTR_TITLE) twice and leaves the annotated title variable unused; this makes the intent slightly harder to read and unnecessarily repeats the lookup. Consider restoring a single lookup that also makes the None check explicit, for example by assigning the result to a local variable (or using the walrus operator with an is not None comparison) before adding it to kwargs.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

I deleted the unused variable. I don't think it's a problem to repeat the lookup. It's consistent with the rest of the function as-is.

Comment on lines +245 to +246
if service.data.get(ATTR_TITLE) is not None:
kwargs[ATTR_TITLE] = service.data.get(ATTR_TITLE)
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The updated ATTR_TITLE logic is only covered via the new script-based test, but there is no direct service call test exercising an explicitly empty string title (e.g., calling notify.notify with title: ''). Adding a unit test similar to test_method_forwards_correct_data that verifies an empty string title is forwarded unchanged for a direct notify service call would better pin down this new behavior and guard against regressions.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

This isn't true, the test I added fails without the corresponding change to the code.

@MartinHjelmare
Copy link
Member

I'm not following where the default title Home Assistant, that you mention, is coming from. There is no default in the changed code, that I can see.

@MartinHjelmare MartinHjelmare marked this pull request as draft February 1, 2026 10:09
@MartinHjelmare MartinHjelmare changed the title allow empty string titles in legacy notifier service Feb 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment