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

Fix to unload all platforms when reloading the integration #604

Merged
merged 3 commits into from
Oct 16, 2021
Merged

Conversation

iMicknl
Copy link
Owner

@iMicknl iMicknl commented Oct 14, 2021

Fix #560

@github-actions github-actions bot added the bug Something isn't working label Oct 14, 2021
default_platforms = [BINARY_SENSOR, SENSOR, SWITCH, NUMBER]

for platform in default_platforms:
platforms[platform] = {}
Copy link
Owner Author

Choose a reason for hiding this comment

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

To be honest, I would like a nicer solution, but I couldn't get it working. Not sure what kind of datastructure we should use..

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don’t like it too. But we can see later to clean this. You can one line if you want:


>>> p = defaultdict(list)
>>> p.update(dict.fromkeys(("a", "b"), [])) # [] and not {}
>>> p
defaultdict(<class 'list'>, {'a': [], 'b': []})

We can also just declare a constant with all the supported platform:

SUPPORTED_PLATFORMS = [BINARY_SENSOR, SENSOR, SWITCH, NUMBER, COVER, ...]

Copy link
Owner Author

Choose a reason for hiding this comment

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

@tetienne I tried the defaultdict approach with the fromkeys(), but that was also not my favourite codestyle :(

Shall we merge this one in for now, and look for a nicer solution? (perhaps during core review)

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about the constant?

I'm OK to merge anyway.

Copy link
Owner Author

Choose a reason for hiding this comment

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

@tetienne I thought about a constant, however we only need it at a single location. That's why I moved it back.

Should we put the constant + comments at the top for readability?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's something I often see within Core. But I will not block for this.

tetienne
tetienne previously approved these changes Oct 14, 2021
@iMicknl
Copy link
Owner Author

iMicknl commented Oct 16, 2021

@iMicknl iMicknl enabled auto-merge (squash) October 16, 2021 20:34
@iMicknl iMicknl disabled auto-merge October 16, 2021 20:40
@iMicknl iMicknl merged commit ea7cbf4 into master Oct 16, 2021
@iMicknl iMicknl deleted the fix/560 branch October 16, 2021 20:40
@tetienne
Copy link
Collaborator

It would be nice yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Config entry has already been setup
2 participants