-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Conversation
@@ -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], [])) |
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.
Would it work to accept [{}]
in the schema? Then we wouldn't need to change cv.ensure_list
.
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 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
.
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.
Right. You mean empty dict, right? Yeah, that's also inconvenient.
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.
Empty dict yes. Guess it's better than fiddling with ensure_list
, which is used everywhere
@@ -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: |
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.
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.
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.
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
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.
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], [])) |
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 we need to accept an empty list specifically. That will be allowed by default.
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.
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] |
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.
that need tests
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.
Do you mean unit tests or test if a dictionary?
…#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
Is it possible this PR is linked to this issue #23424 ? |
Before this it was not even allowed to be configured in a package. They report it stopped working, so unlikely |
Description:
Change person schema to always be a list. Skip an empty
{}
dictRelated 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:
lazytox
If the code does not interact with devices: