Skip to content

Support multiple attachments in signal messenger integration#31141

Merged
rohankapoorcom merged 12 commits into
home-assistant:devfrom
bbernhard:signalmessenger_multiple_attachments
Feb 1, 2020
Merged

Support multiple attachments in signal messenger integration#31141
rohankapoorcom merged 12 commits into
home-assistant:devfrom
bbernhard:signalmessenger_multiple_attachments

Conversation

@bbernhard
Copy link
Copy Markdown
Contributor

@bbernhard bbernhard commented Jan 24, 2020

Breaking change

Proposed change

There was a feature request to support multiple attachments in a single Signal message. (bbernhard/signal-cli-rest-api#5) Unfortunately, this change wasn't possible without a breaking backwards compatibility (at least I haven't found a nice way to accomplish that; suggestions are welcome).

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

see https://www.home-assistant.io/integrations/signal_messenger/

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

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

@bbernhard bbernhard changed the title Signalmessenger multiple attachments support multiple attachments in signal messenger integration Jan 24, 2020
@MartinHjelmare MartinHjelmare changed the title support multiple attachments in signal messenger integration Support multiple attachments in signal messenger integration Jan 25, 2020
filename = None
if data is not None and ATTR_FILENAME in data:
filename = data[ATTR_FILENAME]
filenames = None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer that we avoid the breaking change unnecessarily here.

This could be done by allowing both the attribute filename as well as the attribute filenames to be provided and then internally adding the filename to the list of filenames.

Copy link
Copy Markdown
Contributor Author

@bbernhard bbernhard Jan 27, 2020

Choose a reason for hiding this comment

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

Sounds good to me 👍 I'll adapt the PR, thanks!

Should the attachment option also be mentioned in the documentation then, or would you see that primarily as a way to stay backwards compatible and as something that's not worth mentioning in the documentation?

Copy link
Copy Markdown
Member

@rohankapoorcom rohankapoorcom Jan 27, 2020

Choose a reason for hiding this comment

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

I would mark it as deprecated and log a warning that it's deprecated and will be removed in version x.y.z (pick a version that's like 3 versions out).

If you are using vol to validate the schema of the service call, we have the deprecated validation helper in config_validation

Alternatively we could keep using attachment as the key and accept both a singular string or a list of strings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot for your suggestions, very much appreciated!

I've updated the PR, please let me know if there's anything else that needs to be changed.

(I've also removed the Breaking changes section from the PR description)

Bernhard B added 3 commits January 27, 2020 18:29
* stay backwards compatible by both allowing the "attachment" and
  the "attachments" attribute.
* stay backwards compatible by both allowing the "attachment" and
  the "attachments" attribute.
* added deprecation warning for 'attachment' attribute
Copy link
Copy Markdown
Member

@rohankapoorcom rohankapoorcom left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for incorporating the feedback. The build is breaking though, that will need to be fixed before merge.

@springstan springstan added the dependency Pull requests marked as a dependency upgrade label Feb 1, 2020
@bbernhard
Copy link
Copy Markdown
Contributor Author

Looks good, thanks for incorporating the feedback. The build is breaking though, that will need to be fixed before merge.

Thanks a lot for your suggestions!

I've updated the PR and everything except the codecov/patch seems to be successful now. Not sure what the codecov/patch test is all about nor how to fix it. Any help is appreciated! :)

@springstan
Copy link
Copy Markdown
Member

I've updated the PR and everything except the codecov/patch seems to be successful now. Not sure what the codecov/patch test is all about nor how to fix it. Any help is appreciated! :)

The code coverage shows how much of the code is covered by tests. Therefore, you will have to add another test to hit the target for code coverage. Hope this helps! :)

@rohankapoorcom
Copy link
Copy Markdown
Member

To clarify, codecov/patch is measuring the code coverage of the diff (exactly what changed in this pull request)

@bbernhard
Copy link
Copy Markdown
Contributor Author

bbernhard commented Feb 1, 2020

I've added now 4 tests, but looks like the code coverage is still less than the check expects. Unfortunately, I do not have any experience with code coverage tools, so it's not really clear to me how they calculate the test coverage and what I need to do in order to hit the target.

@rohankapoorcom
Copy link
Copy Markdown
Member

You have to remove your files from the coverage ignore file:

    homeassistant/components/signal_messenger/__init__.py
    homeassistant/components/signal_messenger/notify.py

needs to be removed from https://github.com/home-assistant/home-assistant/blob/dev/.coveragerc#L624

@bbernhard
Copy link
Copy Markdown
Contributor Author

You have to remove your files from the coverage ignore file:

    homeassistant/components/signal_messenger/__init__.py
    homeassistant/components/signal_messenger/notify.py

needs to be removed from https://github.com/home-assistant/home-assistant/blob/dev/.coveragerc#L624

oh, damn...silly me...totally forgot about that. Many thanks!

Hopefully the coverage will now improve 🤞

@rohankapoorcom rohankapoorcom merged commit 294c6a7 into home-assistant:dev Feb 1, 2020
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Please address the comments in a new PR.

assert hass.services.has_service(BASE_COMPONENT, "test")


class TestSignalMesssenger(unittest.TestCase):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

New tests must be async standalone pytest test functions.

recipients = ["+435565656565"]
number = "+43443434343"
client = SignalCliRestApi("http://127.0.0.1:8080", number)
self._signalmessenger = signalmessenger.SignalNotificationService(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should never set up a notify service or create an entity directly. We should always use the core to set up the component and platform. That will make the tests robust.

def test_send_message(self, mock):
"""Test send message."""
message = "Testing Signal Messenger platform :)"
mock.register_uri(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't need to test the library requests. We should patch the library and make sure that we are interfacing with the library correctly.

The library is responsible for testing that it makes the correct requests.

@lock lock Bot locked and limited conversation to collaborators Feb 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

by-code-owner cla-signed dependency Pull requests marked as a dependency upgrade integration: signal_messenger small-pr PRs with less than 30 lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants