8000 Added config validator for future group platforms by cdce8p · Pull Request #12592 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 5 commits into from
Feb 26, 2018
Merged

Added config validator for future group platforms #12592

merged 5 commits into from
Feb 26, 2018

Conversation

cdce8p
Copy link
Member
@cdce8p cdce8p commented Feb 21, 2018

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:

  • The code change is tested and works locally.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

* Check if all entities in string or list belong to domain
* Added tests
@cdce8p cdce8p requested a review from a team as a code owner February 21, 2018 23:44
@cdce8p cdce8p mentioned this pull request Feb 22, 2018
3 tasks
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(',')]
Copy link
Member

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")
Copy link
Member

Choose a reason for hiding this comment

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

Typo

Copy link
Member
@balloob balloob left a 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():
Copy link
Member

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.

@cdce8p
Copy link
Member Author
cdce8p commented Feb 22, 2018

@balloob There are already several PR's open, some even Ready for review. It would make merging them easier if all can use the same validator function.

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")
Copy link
Member

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."""
Copy link
Member

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 (entitiyentity)

Copy link
Member Author

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.

Copy link
Member
@pvizeli pvizeli left a 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
@cdce8p
Copy link
Member Author
cdce8p commented Feb 25, 2018

@pvizeli Added entity_domain to the image_processing platform. As mentioned in the chat: The notification.group component doesn't check the domain, since the service only takes the name as input and assumes it belongs to notify.

@balloob balloob merged commit 6e6ae17 into home-assistant:dev Feb 26, 2018
@cdce8p cdce8p deleted the cv-EntitiesDomain branch February 26, 2018 12:01
OttoWinter added a commit to OttoWinter/home-assistant that referenced this pull request Feb 27, 2018
balloob pushed a commit that referenced this pull request Mar 2, 2018
* 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.
@balloob balloob mentioned this pull request Mar 9, 2018
@home-assistant home-assistant locked and limited conversation to collaborators May 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0