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

Person schema for merge_packages #21307 #21703

Merged
merged 10 commits into from
Apr 3, 2019
Merged

Conversation

kellerza
Copy link
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
@@ -50,7 +50,7 @@
})

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
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
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
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
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

@kellerza kellerza changed the title [WIP] Person schema for merge_packages #21307 Person schema for merge_packages #21307 Mar 8, 2019
@@ -80,6 +81,8 @@ def __init__(self, hass: HomeAssistantType, component: EntityComponent,

config_data = self.config_data = OrderedDict()
for conf in config_persons:
if not conf:
Copy link
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
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
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

@@ -50,7 +50,8 @@
})

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
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
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!

@@ -349,6 +349,11 @@ def positive_timedelta(value: timedelta) -> timedelta:
return value


def remove_falsy(value: Sequence[T]) -> Sequence[T]:
"""Remove falsy values from a list."""
return [v for v in value if v]
Copy link
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
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
unibeck pushed a commit to unibeck/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
unibeck pushed a commit to unibeck/home-assistant that referenced this pull request Apr 7, 2019
@oncleben31
Copy link
Contributor

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

@kellerza
Copy link
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