Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support notification_id in notify.persistent_notification #74822

Merged
merged 2 commits into from Jun 26, 2023

Conversation

KevinCathcart
Copy link
Contributor

@KevinCathcart KevinCathcart commented Jul 9, 2022

Breaking change

Proposed change

Adds support for notification_id as a data field. As discussed in issue #68811, this is relevant in some scenarios such as when using the Alert integration, which you would prefer to update the existing notification instead of potentially creating a large number of persistent_notification entities.

Code wise this is pretty straightforward. Rather than updating the voluptuous schema for this service, I've just used the existing notify schema to make this act the same as the real platform implementations.

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

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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

To help with the load of incoming pull requests:

@KevinCathcart KevinCathcart requested a review from a team as a code owner July 9, 2022 17:34
@project-bot project-bot bot added this to Needs review in Dev Jul 9, 2022
@probot-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!
(message by CodeOwnersMention)

@ScottG489

This comment was marked as off-topic.

@KevinCathcart

This comment was marked as off-topic.

@ScottG489

This comment was marked as off-topic.

@oxc

This comment was marked as off-topic.

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Dec 20, 2022
@github-actions
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Mar 28, 2023
@oxc
Copy link

oxc commented Mar 28, 2023

Still relevant.

@github-actions github-actions bot removed the stale label Apr 21, 2023
@ScottG489
Copy link
Contributor

@KevinCathcart Could you resolve the merge conflicts in this PR? Anything to help increase the chance of this getting reviewed and merged.

@ScottG489
Copy link
Contributor

ScottG489 commented Jun 8, 2023

So now that I have some core dev experience, I think I'm able to follow what the code in this PR is doing and can provide an informed review.

So the appropriate data field is added to the services.yaml definition to have this notify service align with a notify interface (as documented here).

In the code itself, we check to see if the data field was included on the notify service call, and if it is we pull the notification_id off of it and use it along with the other fields to create the persistent notification. Additionally, when the notify service is registered, we correctly use a schema representative of a notify service (it seems like this schema should be centralized for all notification services to share to avoid situations like this where we have notification services that don't adhere to the interface).

Finally, the test to me looks pretty good. It's creating 2 persistent notifications via the notify.persistent_notification service with the same notification_id. It's then validating that there is only 1 persistent notification, which there should be since the second notification will overwrite the first. The test is also verifying that the notification has the message and title from the second notification, further showing that it overwrites the first.

@ScottG489
Copy link
Contributor

I just realized a potential issue with the tests in this PR. When validating the created persistent notifications, we are getting an entity from states. However, with recent changes, persistent notifications will no longer be stored in states.

I'll try to find out the proper way to fetch persistent notification information.

@ScottG489
Copy link
Contributor

Ok I think the answer actually lies with test changes that would be present if this PR were to be synced with dev. I'm going to suggest some changes.

Copy link
Contributor

@ScottG489 ScottG489 left a comment

Choose a reason for hiding this comment

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

Tested these changes locally. Tests passing with 100% cover to applicable files.

While I was at it I also spun this up with hass and I can confirm it's working as expected. The service has a data field now and when notification_id is specified it will replace existing notifications with that id and calling persistent_notification.dismiss with that id will remove it.

tests/components/notify/test_persistent_notification.py Outdated Show resolved Hide resolved
tests/components/notify/test_persistent_notification.py Outdated Show resolved Hide resolved
tests/components/notify/test_persistent_notification.py Outdated Show resolved Hide resolved
tests/components/notify/test_persistent_notification.py Outdated Show resolved Hide resolved
Dev automation moved this from Needs review to Review in progress Jun 9, 2023
Dev automation moved this from Review in progress to Reviewer approved Jun 26, 2023
@balloob balloob merged commit d700415 into home-assistant:dev Jun 26, 2023
47 checks passed
Dev automation moved this from Reviewer approved to Done Jun 26, 2023
@ScottG489
Copy link
Contributor

馃檹馃檹馃檹

@github-actions github-actions bot locked and limited conversation to collaborators Jun 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed core has-tests integration: notify new-feature small-pr PRs with less than 30 lines. smash Indicator this PR is close to finish for merging or closing
Projects
Dev
  
Done
6 participants