Skip to content

Person schema for merge_packages #21307#21703

Merged
balloob merged 10 commits intohome-assistant:devfrom
kellerza:person
Apr 3, 2019
Merged

Person schema for merge_packages #21307#21703
balloob merged 10 commits intohome-assistant:devfrom
kellerza:person

Conversation

@kellerza
Copy link
Copy Markdown
Member

@kellerza kellerza commented Mar 6, 2019

Description:

Change person schema to always be a list. Skip an empty {} dict

Related issue (if applicable): fixes #21307

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>

Example entry for configuration.yaml (if applicable):

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with lazytox
  • There is no commented out code in this PR.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@kellerza kellerza requested a review from a team as a code owner March 6, 2019 05:21
@ghost ghost assigned kellerza Mar 6, 2019
@ghost ghost added the in progress label Mar 6, 2019

CONFIG_SCHEMA = vol.Schema({
vol.Optional(DOMAIN): vol.Any(vol.All(cv.ensure_list, [PERSON_SCHEMA]), {})
vol.Optional(DOMAIN): vol.All(cv.ensure_list, vol.Any([PERSON_SCHEMA], []))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it work to accept [{}] in the schema? Then we wouldn't need to change cv.ensure_list.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess it could, but will have to put in a specific check in person's setup to ignore empty lists, likely here: if not conf: continue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right. You mean empty dict, right? Yeah, that's also inconvenient.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Empty dict yes. Guess it's better than fiddling with ensure_list, which is used everywhere

Comment thread homeassistant/components/person/__init__.py Outdated
@kellerza kellerza changed the title [WIP] Person schema for merge_packages #21307 Person schema for merge_packages #21307 Mar 8, 2019
Comment thread homeassistant/components/person/__init__.py Outdated

config_data = self.config_data = OrderedDict()
for conf in config_persons:
if not conf:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is weird. I think that this is a flaw in packages and should not be fixed in the person component. That means that any other integration in the future will need to add checks in case packages are used, that's wrong.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

An alternative is that ensure_list should return [] for an empty config branch.

It’s supposed to be null, but with our Yaml loader we convert an empty branch to an empty OrderedDict

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a `remove_falsy' validator to fix this. Also rolled back changes to the tests to show it has no impact

CONFIG_SCHEMA = vol.Schema({
vol.Optional(DOMAIN): vol.Any(vol.All(cv.ensure_list, [PERSON_SCHEMA]), {})
vol.Optional(DOMAIN): vol.All(
cv.ensure_list, cv.remove_falsy, vol.Any([PERSON_SCHEMA], []))
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare Apr 2, 2019

Choose a reason for hiding this comment

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

I don't think we need to accept an empty list specifically. That will be allowed by default.

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Looks good!


def remove_falsy(value: Sequence[T]) -> Sequence[T]:
"""Remove falsy values from a list."""
return [v for v in value if v]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

that need tests

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do you mean unit tests or test if a dictionary?

@balloob balloob merged commit 3453d67 into home-assistant:dev Apr 3, 2019
@ghost ghost removed the in progress label Apr 3, 2019
kellerza added a commit that referenced this pull request Apr 3, 2019
@kellerza kellerza deleted the person branch April 3, 2019 03:37
jonbeckman pushed a commit to jonbeckman/home-assistant that referenced this pull request Apr 7, 2019
…#21703)

* Person schema for merge_packages home-assistant#21307

* empty list

* skip empty persons

* hound

* test schema

* ensure_none

* remove any test changes

* remove_falsy validator

* nice!

* coretests
jonbeckman pushed a commit to jonbeckman/home-assistant that referenced this pull request Apr 7, 2019
@oncleben31
Copy link
Copy Markdown
Contributor

Is it possible this PR is linked to this issue #23424 ?

@kellerza
Copy link
Copy Markdown
Member Author

Before this it was not even allowed to be configured in a package. They report it stopped working, so unlikely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Person cannot be merged (Packages)

8 participants