-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Added config validator for future group platforms #12592
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
Conversation
* Check if all entities in string or list belong to domain * Added tests
if value is None or value == []: | ||
raise vol.Invalid("Entities can not be None") | ||
if isinstance(value, str): | ||
value = [ent_id for ent_id in value.split(',')] |
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.
Instead of this, run it through the entity_ids
validator
if split_entity_id(ent_id)[0] == self.domain: | ||
entities.append(ent_id) | ||
else: | ||
raise vol.Invalid("Entity ID does not belog to domain") |
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.
Typo
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 should not add code without it being used in something. So we should get one of the group platform PRs to adopt this.
@@ -147,6 +147,31 @@ def entity_ids(value: Union[str, Sequence]) -> Sequence[str]: | |||
return [entity_id(ent_id) for ent_id in value] | |||
|
|||
|
|||
class EntitiesDomain(): |
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 don't think you need a class. You can make a factory function (nested) where the outer function takes the domain and the inner the entities as parameters. This pattern is already used here in config validation.
@balloob There are already several PR's open, some even |
values = entity_ids(values) | ||
for ent_id in values: | ||
if split_entity_id(ent_id)[0] != domain: 10000 | ||
raise vol.Invalid("Entity ID does not belong to domain") |
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.
From my past experience voluptuous is not that great at reporting where exactly a validation error occured, and having a message like this can be quite cryptic without context. This is only a suggestion: could you maybe also print out the entity_id and the domain it's supposed to be in?
def entities_domain(domain: str): | ||
"""Validate that entities belong to domain.""" | ||
def validate(values: Union[str, Sequence]) -> Sequence[str]: | ||
"""Test if entitiy domain is domain.""" |
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.
Sorry for annoying you, but this is a spelling mistake (entitiy
→ entity
)
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.
No, you are right. I'll fix that.
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.
Add this to image_processing platform and we are fine to merge this 👍 and also to notification.group
* Image_processing platform now uses cv.entity_domain for source validation
@pvizeli Added |
... by rebasing onto home-assistant#12592
* Add grouped_light platform * 📝 Fix Lint issues * 🎨 Reformat code with yapf * A Few changes * ✨ Python 3.5 magic * Improvements Included the comments from #11323 * Fixes * Updates * Fixes & Tests * Fix bad-whitespace * Domain Config Validation ... by rebasing onto #12592 * Style changes & Improvements * Lint * Changes according to Review Comments * Use blocking light.async_turn_* * Revert "Use blocking light.async_turn_*" This reverts commit 9e83198. * Update service calls and state reporting * Add group service call tests * Remove unused constant.
Description:
As response to home-assistant/architecture#13 (comment) I added a first version of entities domain validation to
helpers/config_validation
so that other PR's for different group platforms can start using it.Different group platforms currently as PR:
Related issue (if applicable): home-assistant/architecture#13
Checklist:
If the code does not interact with devices:
tox
run successfully. Your PR cannot be merged unless tests pass