-
-
Notifications
You must be signed in to change notification settings - Fork 36.7k
Allow empty string titles in legacy notifier service #161985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this 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_serviceto treatATTR_TITLEas present whenever it is notNone, 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. |
| if service.data.get(ATTR_TITLE) is not None: | ||
| kwargs[ATTR_TITLE] = service.data.get(ATTR_TITLE) |
Copilot
AI
Jan 31, 2026
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| if service.data.get(ATTR_TITLE) is not None: | ||
| kwargs[ATTR_TITLE] = service.data.get(ATTR_TITLE) |
Copilot
AI
Jan 31, 2026
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
I'm not following where the default title |
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 withtitle: Home AssistantWhy 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
Nonetitles (i.e. missing title key in yaml configuration): #3100This was followed up by some hotfix patch that introduced the current logic (almost 10 years ago!), which I believe accidentally conflates
Nonewith""by using the truthiness of strings, rather than comparing toNonedirectly: #3302In this PR, I've just swapped the truthiness check for a direct comparison to
None, exactly as we do a few lines below forATTR_TARGET.Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: