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

Fix discord embed class initialization #67831

Merged
merged 1 commit into from
Mar 9, 2022

Conversation

cheng2wei
Copy link
Contributor

Proposed change

Changeset #66540 broke the discord notification integration when trying to use the 'embed'/'thumbnail'/'author' fields. This is due to a breaking change in the constructor of the Embed class when moving from discord.py 1.7.3 to nextcord. The proposed change creates an Embed class using the new constructor.

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

Additional information

I created a custom component that overrides the default discord integration and validated that I was getting discord notifications with the example embedded YAML configuration mentioned in the documentation.

service: notify.discord
data:
message: ""
target: ["1234567890", "0987654321"]
data:
embed:
title: 'title'
description: 'description'
url: 'https://www.home-assistant.io/'
color: 199363
author:
name: 'Author Home Assistant'
url: 'https://www.home-assistant.io/'
icon_url: 'https://www.home-assistant.io/images/favicon-192x192-full.png'
footer:
text: 'Footer Text'
icon_url: 'https://www.home-assistant.io/'
thumbnail:
url: 'https://www.home-assistant.io/images/favicon-192x192-full.png'
fields:
- name: 'fieldname1'
value: 'valuename1'
inline: false
- name: 'fieldname2'
value: 'valuename2'
- name: 'fieldname3'
value: 'valuename3'
- name: 'fieldname4'
value: 'valuename4'
inline: false

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:

@homeassistant
Copy link
Contributor

Hi @cheng2wei,

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!

@project-bot project-bot bot added this to Needs review in Dev Mar 8, 2022
fields = embedding.get(ATTR_EMBED_FIELDS) or []

if embedding:
embed = nextcord.Embed(**embedding)
embed = nextcord.Embed(
Copy link
Contributor

Choose a reason for hiding this comment

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

I see there is also Embed.from_dict which looks like it may do exactly what we want?
https://nextcord.readthedocs.io/en/latest/api.html#nextcord.Embed.from_dict
and reading the implementation it seems to do exactly what this function is doing:
https://github.com/nextcord/nextcord/blob/408862e24c11bf7d7a95a56d2eb2532094845404/nextcord/embeds.py#L209

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I was looking at this as well. Functionally, from_dict works. My only concern is that there are other keys that also work in the dict that are not documented in the home assistant documentation, which would be more of a feature-add. This would mean any time the nextcord library is upgraded and introduces more fields, the documentation would need to be updated as well.

For the scope of this PR, I just wanted to align back to the previous working behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree that we don't want to be chasing documentation. It seems like we should be able to either limit to fields specified in this file, or update the docs to point to the nextcoord docs, or not worry about it.

Just to be clear i am not thrilled with how verbose this is given it can be replaced with a single line. I am also not sure that any documentation needs to be updated at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fair. It is rather verbose.

The new keynames that would be accepted are 'video', 'provider', and 'image'. (Not sure how the image key is different from the one that exists outside of Embed). These are not documented by home assistant, and would need to be filtered out until those features are tested.

We could use from_dict and provide a dictionary that has been filtered with an allow-list of tested features. That would also work to reduce all of the embed.set_* calls.

Is this something that you want accomplished in this PR? My rationale was just to make the smallest change possible to unblock the integration from working.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I were doing this I would just add the from dict call and I wouldn't worry about the docs personally.

My second choice would add it with a one line filter by the set of allowed keys already referenced here.

I don't consider either of these very big. Though the smallest change word be to rollback the broken move to nextcoord since it didn't really work.

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't intend for this to be a big deal as I thought it would be fast to switch to. I'll merge this and we can deal with it in a follow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi apologies, it's not a big deal! I just don't have spare cycles at the moment to keep working on it. I can revisit this in a week or so and look into the additional features as well.

Copy link
Contributor

@allenporter allenporter left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this, I really appreciate it. 馃憤馃徏

Dev automation moved this from Needs review to Reviewer approved Mar 8, 2022
@balloob balloob added this to the 2022.3.4 milestone Mar 8, 2022
@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Mar 8, 2022
@allenporter allenporter merged commit 3638539 into home-assistant:dev Mar 9, 2022
Dev automation moved this from Reviewer approved to Done Mar 9, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix cherry-picked cla-signed integration: discord small-pr PRs with less than 30 lines. smash Indicator this PR is close to finish for merging or closing
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

Discord notification unable to add thumbnails or fields in 2022.3
5 participants