-
-
Notifications
You must be signed in to change notification settings - Fork 38k
Validate light supported_color_modes #48247
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
Closed
emontnemery
wants to merge
1
commit into
home-assistant:dev
from
emontnemery:light_validate_supported_color_modes
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,20 @@ | |
| COLOR_MODES_BRIGHTNESS = VALID_COLOR_MODES - {COLOR_MODE_ONOFF} | ||
| COLOR_MODES_COLOR = {COLOR_MODE_HS, COLOR_MODE_RGB, COLOR_MODE_XY} | ||
|
|
||
|
|
||
| def validate_supported_color_modes(color_modes): | ||
| """Validate the given color modes.""" | ||
| color_modes = set(color_modes) | ||
| if ( | ||
| not color_modes | ||
| or COLOR_MODE_UNKNOWN in color_modes | ||
| or (COLOR_MODE_BRIGHTNESS in color_modes and len(color_modes) > 1) | ||
| or (COLOR_MODE_ONOFF in color_modes and len(color_modes) > 1) | ||
| ): | ||
| raise vol.Error(f"Invalid supported_color_modes {sorted(color_modes)}") | ||
| return color_modes | ||
|
|
||
|
|
||
| # Float that represents transition time in seconds to make change. | ||
| ATTR_TRANSITION = "transition" | ||
|
|
||
|
|
@@ -609,9 +623,16 @@ def capability_attributes(self): | |
| if supported_features & SUPPORT_EFFECT: | ||
| data[ATTR_EFFECT_LIST] = self.effect_list | ||
|
|
||
| data[ATTR_SUPPORTED_COLOR_MODES] = sorted( | ||
| self._light_internal_supported_color_modes | ||
| ) | ||
| supported_color_modes = self._light_internal_supported_color_modes | ||
| try: | ||
| supported_color_modes = validate_supported_color_modes( | ||
| supported_color_modes | ||
| ) | ||
| except vol.Error as ex: | ||
| _LOGGER.warning("Light %s: %s", self.entity_id, ex) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may spam a lot, should the warning be limited to once per entity? |
||
| supported_color_modes = {COLOR_MODE_ONOFF} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of this, should the state update be rejected? |
||
|
|
||
| data[ATTR_SUPPORTED_COLOR_MODES] = sorted(supported_color_modes) | ||
|
|
||
| return data | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We don't validate attributes at runtime as it can get too costly to do it for everything. Instead I once had this idea #37663
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.
In this particular case, it's a capability attribute which should rarely change, if ever.
If the attribute has not changed, there's no need to re-validate.
In #37663 it's mentioned that:
So it's opt-in per integration? Can't it be done in base components instead?