-
-
Notifications
You must be signed in to change notification settings - Fork 29k
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
Conversation
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! |
fields = embedding.get(ATTR_EMBED_FIELDS) or [] | ||
|
||
if embedding: | ||
embed = nextcord.Embed(**embedding) | ||
embed = nextcord.Embed( |
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 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?
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.
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.
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.
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.
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.
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.
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.
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.
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 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.
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.
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.
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.
Thank you for fixing this, I really appreciate it. 馃憤馃徏
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
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.
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
python3 -m script.hassfest
.requirements_all.txt
. Updated by runningpython3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: