Skip to content

Ensure we have valid config AFTER merging packages #13015#13038

Merged
balloob merged 2 commits intohome-assistant:devfrom
kellerza:packagesnull
Mar 10, 2018
Merged

Ensure we have valid config AFTER merging packages #13015#13038
balloob merged 2 commits intohome-assistant:devfrom
kellerza:packagesnull

Conversation

@kellerza
Copy link
Copy Markdown
Member

Description:

My initial diagnosis for #13015 did not include empty components inside packages

This fixes it for #13015 and check_config which will currently suffer from the same fate

Example entry for configuration.yaml (if applicable):

homeassistant:
   packages:
      one:
         python_script:

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

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 10, 2018 06:22
@homeassistant homeassistant added core small-pr PRs with less than 30 lines. cla-signed labels Mar 10, 2018
@kellerza kellerza added this to the 0.65.2 milestone Mar 10, 2018

# Ensure we have no None values after merge
for key, value in config.items():
if not value:
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.

PEP8 recommends:

Also, beware of writing if x when you really mean if x is not None -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context!

for key, value in config.items():
    if value is None:
        config[key] = {}

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 think my version might be equal to: config[key] = value or {}, which is the correct behaviour

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.

Or let correct by saying current behaviour

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.

Ok, but then the comment should rather be:

# Ensure we have no None, empty or false values after merge
for key, value in config.items():
    if not value:
        config[key] = {}

@balloob balloob merged commit 40485a6 into home-assistant:dev Mar 10, 2018
balloob pushed a commit that referenced this pull request Mar 10, 2018
* Ensure we have valid config AFTER merging packages #13015

* also fix packages
@balloob balloob mentioned this pull request Mar 10, 2018
@kellerza kellerza deleted the packagesnull branch March 18, 2018 19:30
@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed core small-pr PRs with less than 30 lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants