Skip to content

Load HA core config from storage#23872

Merged
balloob merged 7 commits intohome-assistant:devfrom
emontnemery:store_core_config
May 16, 2019
Merged

Load HA core config from storage#23872
balloob merged 7 commits intohome-assistant:devfrom
emontnemery:store_core_config

Conversation

@emontnemery
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery commented May 14, 2019

Description:

Initial steps of home-assistant/architecture#176:

  • Load core config from storage
  • Still support YAML, which will override config in storage

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the [development checklist][dev-checklist]

If user exposed functionality or configuration variables are added/changed:

If the code does not interact with devices:

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

Comment thread homeassistant/config.py Outdated
Comment thread homeassistant/config.py Outdated
Comment thread homeassistant/config.py
Comment thread homeassistant/config.py
Comment thread homeassistant/config.py Outdated
Comment thread homeassistant/config.py Outdated
Comment thread homeassistant/config.py Outdated
Comment thread homeassistant/config.py Outdated
Comment thread homeassistant/core.py Outdated
@emontnemery
Copy link
Copy Markdown
Contributor Author

emontnemery commented May 15, 2019

Thanks @balloob and @awarecan for reviewing, all fixed.

Comment thread homeassistant/config.py
_LOGGER.error("Received invalid time zone %s", time_zone_str)
if any([k in config for k in [
CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, CONF_ELEVATION,
CONF_TIME_ZONE, CONF_UNIT_SYSTEM]]):
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.

Creating a list is unnecessary here (https://twitter.com/raymondh/status/1125487457443532800). Admittedly, this is a micro-optimization though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's even a pico-optimization ;)
Do you have a suggestion for a cleaner way to do it though?

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.

What do you mean? You just have to remove the [] so that the call inside any is a generator, not a list

Comment thread homeassistant/config.py Outdated
if data:
hac = hass.config
hac.config_source = SOURCE_STORAGE
hac.latitude = data['latitude']
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.

How will this handle users backrolling? If we decide to change the schema here, some of these keys might be invalid. If a user then tries backporting to a version before the schema change this will raise an exception - and since this is core code it could (I think) stop HA from starting up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, how about validating the data with a schema, and rejecting it if it doesn't pass?

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.

Yeah that could probably work

@emontnemery emontnemery changed the title WIP - Load HA core config from storage Load HA core config from storage May 16, 2019
Comment thread homeassistant/config.py Outdated
Comment thread tests/test_config.py Outdated
Comment thread tests/test_config.py Outdated
Copy link
Copy Markdown
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.

Ok to merge when final comment addressed!

@balloob balloob merged commit c2fc8a0 into home-assistant:dev May 16, 2019
@balloob balloob mentioned this pull request Jun 4, 2019
@emontnemery emontnemery deleted the store_core_config branch September 6, 2019 10:02
alandtse pushed a commit to alandtse/home-assistant that referenced this pull request Oct 12, 2019
* Load HA core config from storage

* Tweak

* Lint, review comments

* Fix test

* Add tests

* Lint

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants