Skip to content

Fire event when core config is updated#23922

Merged
emontnemery merged 5 commits intohome-assistant:devfrom
emontnemery:fire_on_core_update
May 20, 2019
Merged

Fire event when core config is updated#23922
emontnemery merged 5 commits intohome-assistant:devfrom
emontnemery:fire_on_core_update

Conversation

@emontnemery
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery commented May 16, 2019

Description:

  • Fire event when core config is updated
  • Support updating core config
  • Store core config in update

This is a follow-up to #23872

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

If the code does not interact with devices:

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

Comment thread homeassistant/core.py Outdated
Comment thread homeassistant/core.py Outdated
Comment thread homeassistant/core.py Outdated
Comment thread homeassistant/core.py Outdated
Comment thread homeassistant/core.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 tests added and last comments addressed

Comment thread homeassistant/core.py Outdated

def set_time_zone(self, time_zone_str: Optional[str]) -> None:
"""Help to set the time zone."""
if time_zone_str is None:
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.

Let's remove this check and instead not call this function if it's none

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.

Fixed.

Comment thread homeassistant/core.py Outdated
self.time_zone = time_zone
dt_util.set_default_time_zone(time_zone)
else:
_LOGGER.error("Received invalid time zone %s", time_zone_str)
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.

Let's raise value error

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.

Fixed + test added.

Comment thread homeassistant/core.py
Comment thread homeassistant/core.py Outdated

Async friendly.
"""
from homeassistant.config import SOURCE_STORAGE
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.

Let's store the constant either in const or at top of this file

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.

Fixed

Comment thread homeassistant/config.py Outdated
mfa_conf))

await async_load_ha_core_config(hass)
await hass.config.load()
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.

Can we rename this async_load, in line with other function names that are async.

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.

Fixed.

Comment thread tests/test_config.py
await hass.config.update(latitude=50)

new_core_data = dict(core_data)
new_core_data['data']['latitude'] = 50
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.

dict on the previous line is not a deep copy of the dictionary. This line is changing the original data.

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.

Fixed.

Comment thread tests/test_config.py Outdated
async def test_loading_configuration_from_packages(hass):
"""Test loading packages config onto hass object config."""
hass.config = mock.Mock()
hass.config.load.return_value = asyncio.Future()
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.

you should be able to drop this. Storage is mocked out in all function based tests.

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.

Yes, fixed.

Comment thread tests/test_core.py Outdated
with pytest.raises(AssertionError):
self.config.is_allowed_path(None)

def test_event_on_update(self):
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.

let's not add new tests that are connected to a class.

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.

Fixed.

Comment thread tests/test_core.py Outdated
def setUp(self):
"""Set up things to be run when tests are started."""
self.config = ha.Config()
self.hass = get_test_home_assistant()
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.

Now all tests in this class are getting a HA instance created.

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, fixed now.

@emontnemery emontnemery merged commit afe9fc2 into home-assistant:dev May 20, 2019
@awarecan
Copy link
Copy Markdown
Contributor

@emontnemery
Copy link
Copy Markdown
Contributor Author

emontnemery commented May 20, 2019

@awarecan Yes i saw that, but it's caused by #24001, not by this PR.

@balloob balloob mentioned this pull request Jun 4, 2019
@emontnemery emontnemery deleted the fire_on_core_update branch September 6, 2019 10:02
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.

4 participants