mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Fix load of components without any config from packages (#9901)
* Fix load of components without any config from packages - Add 'None' to the packages config schema validation, to be able to load components without any more configuration from yaml package files, like `wake_on_lan`, `media_extractor` and so on. * test the ability to load components without configuration from packages
This commit is contained in:
parent
3de95c068a
commit
875edef3f0
@ -123,7 +123,7 @@ http_password: welcome
|
||||
|
||||
PACKAGES_CONFIG_SCHEMA = vol.Schema({
|
||||
cv.slug: vol.Schema( # Package names are slugs
|
||||
{cv.slug: vol.Any(dict, list)}) # Only slugs for component names
|
||||
{cv.slug: vol.Any(dict, list, None)}) # Only slugs for component names
|
||||
})
|
||||
|
||||
CUSTOMIZE_CONFIG_SCHEMA = vol.Schema({
|
||||
|
@ -442,6 +442,38 @@ class TestConfig(unittest.TestCase):
|
||||
assert self.hass.config.units.name == CONF_UNIT_SYSTEM_METRIC
|
||||
assert self.hass.config.time_zone.zone == 'America/New_York'
|
||||
|
||||
def test_loading_configuration_from_packages(self):
|
||||
"""Test loading packages config onto hass object config."""
|
||||
self.hass.config = mock.Mock()
|
||||
|
||||
run_coroutine_threadsafe(
|
||||
config_util.async_process_ha_core_config(self.hass, {
|
||||
'latitude': 39,
|
||||
'longitude': -1,
|
||||
'elevation': 500,
|
||||
'name': 'Huis',
|
||||
CONF_TEMPERATURE_UNIT: 'C',
|
||||
'time_zone': 'Europe/Madrid',
|
||||
'packages': {
|
||||
'package_1': {'wake_on_lan': None},
|
||||
'package_2': {'light': {'platform': 'hue'},
|
||||
'media_extractor': None,
|
||||
'sun': None}},
|
||||
}), self.hass.loop).result()
|
||||
|
||||
# Empty packages not allowed
|
||||
with pytest.raises(MultipleInvalid):
|
||||
run_coroutine_threadsafe(
|
||||
config_util.async_process_ha_core_config(self.hass, {
|
||||
'latitude': 39,
|
||||
'longitude': -1,
|
||||
'elevation': 500,
|
||||
'name': 'Huis',
|
||||
CONF_TEMPERATURE_UNIT: 'C',
|
||||
'time_zone': 'Europe/Madrid',
|
||||
'packages': {'empty_package': None},
|
||||
}), self.hass.loop).result()
|
||||
|
||||
@mock.patch('homeassistant.util.location.detect_location_info',
|
||||
autospec=True, return_value=location_util.LocationInfo(
|
||||
'0.0.0.0', 'US', 'United States', 'CA', 'California',
|
||||
@ -541,6 +573,7 @@ def test_merge(merge_log_err):
|
||||
'pack_11': {'input_select': {'is1': None}},
|
||||
'pack_list': {'light': {'platform': 'test'}},
|
||||
'pack_list2': {'light': [{'platform': 'test'}]},
|
||||
'pack_none': {'wake_on_lan': None},
|
||||
}
|
||||
config = {
|
||||
config_util.CONF_CORE: {config_util.CONF_PACKAGES: packages},
|
||||
@ -550,10 +583,11 @@ def test_merge(merge_log_err):
|
||||
config_util.merge_packages_config(config, packages)
|
||||
|
||||
assert merge_log_err.call_count == 0
|
||||
assert len(config) == 4
|
||||
assert len(config) == 5
|
||||
assert len(config['input_boolean']) == 2
|
||||
assert len(config['input_select']) == 1
|
||||
assert len(config['light']) == 3
|
||||
assert config['wake_on_lan'] is None
|
||||
|
||||
|
||||
def test_merge_new(merge_log_err):
|
||||
|
Loading…
x
Reference in New Issue
Block a user