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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add device triggers to the Monzo integration #119214

Draft
wants to merge 17 commits into
base: dev
Choose a base branch
from

Conversation

JakeMartin-ICL
Copy link
Contributor

@JakeMartin-ICL JakeMartin-ICL commented Jun 9, 2024

Proposed change

This adds device triggers to the Monzo integration, allowing triggering automations when a transaction is made on an account.

To achieve this, webhooks are registered during setup with the Monzo API for each account, which fires an event, which triggers the device trigger. The webhooks are tidied up on integration removal and at each start and teardown we clear all webhooks from the Monzo API matching the host associated with this instance.

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
  • 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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

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.

There is a merge conflict.

Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

This code looks familiar :P

Instead of using device triggers, have you considered using event entities?

@JakeMartin-ICL
Copy link
Contributor Author

I've extracted the dependency bump and the change to config_entries into their own PRs to go in first:

@JakeMartin-ICL
Copy link
Contributor Author

This code looks familiar :P

Instead of using device triggers, have you considered using event entities?

Yep, thanks for setting great examples :D

Yeah, but although I like the everything-is-an-entity model on the backend, I think device triggers are much more intuitive for users on the frontend, at least for now.

@JakeMartin-ICL JakeMartin-ICL force-pushed the monzo-add-device-triggers branch 2 times, most recently from 0546d02 to a0ad89b Compare June 11, 2024 12:44
@JakeMartin-ICL JakeMartin-ICL marked this pull request as ready for review June 11, 2024 19:48
@JakeMartin-ICL JakeMartin-ICL requested a review from a team as a code owner June 11, 2024 19:48
homeassistant/config_entries.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft June 12, 2024 04:42
@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.

@JakeMartin-ICL JakeMartin-ICL marked this pull request as ready for review June 12, 2024 09:30
@JakeMartin-ICL JakeMartin-ICL marked this pull request as draft July 17, 2024 15:36
@JakeMartin-ICL JakeMartin-ICL marked this pull request as ready for review July 23, 2024 22:27
homeassistant/components/monzo/__init__.py Outdated Show resolved Hide resolved
tests/components/monzo/conftest.py Outdated Show resolved Hide resolved
tests/components/monzo/test_device_trigger.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft September 4, 2024 18:20
@JakeMartin-ICL JakeMartin-ICL force-pushed the monzo-add-device-triggers branch 3 times, most recently from ebc20d6 to 0ca22ef Compare September 21, 2024 10:36
@emontnemery
Copy link
Contributor

@JakeMartin-ICL To make this PR move, address the review comments, and don't forget to click the "Ready for review" button when you want the PR to be reviewed again. If you don't agree or understand some comment, reply to it.

@JakeMartin-ICL JakeMartin-ICL marked this pull request as ready for review October 18, 2024 15:19
Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

The added webhook management is lacking in test coverage, can that be improved?
Also, please add translations in monzo/strings.json for the device trigger

@emontnemery emontnemery marked this pull request as draft November 8, 2024 13:06
@emontnemery
Copy link
Contributor

Please consider the new review comments, and don't forget to click the "Ready for review" button once you've addressed them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants