def test_core_config_schema(): """Test core config schema.""" for value in ( { CONF_UNIT_SYSTEM: "K" }, { "time_zone": "non-exist" }, { "latitude": "91" }, { "longitude": -181 }, { "external_url": "not an url" }, { "internal_url": "not an url" }, {"currency", 100}, { "customize": "bla" }, { "customize": { "light.sensor": 100 } }, { "customize": { "entity_id": [] } }, ): with pytest.raises(MultipleInvalid): config_util.CORE_CONFIG_SCHEMA(value) config_util.CORE_CONFIG_SCHEMA({ "name": "Test name", "latitude": "-23.45", "longitude": "123.45", "external_url": "https://www.example.com", "internal_url": "http://example.local", CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_METRIC, "currency": "USD", "customize": { "sensor.temperature": { "hidden": True } }, })
def test_core_config_schema_internal_external_warning(caplog): """Test that we warn for internal/external URL with path.""" config_util.CORE_CONFIG_SCHEMA({ "external_url": "https://www.example.com/bla", "internal_url": "http://example.local/yo", }) assert "Invalid external_url set" in caplog.text assert "Invalid internal_url set" in caplog.text
def test_core_config_schema(self): """Test core config schema.""" for value in ( { CONF_UNIT_SYSTEM: 'K' }, { 'time_zone': 'non-exist' }, { 'latitude': '91' }, { 'longitude': -181 }, { 'customize': 'bla' }, { 'customize': { 'invalid_entity_id': {} } }, { 'customize': { 'light.sensor': 100 } }, ): with pytest.raises(MultipleInvalid): config_util.CORE_CONFIG_SCHEMA(value) config_util.CORE_CONFIG_SCHEMA({ 'name': 'Test name', 'latitude': '-23.45', 'longitude': '123.45', CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_METRIC, 'customize': { 'sensor.temperature': { 'hidden': True, }, }, })
def test_core_config_schema(): """Test core config schema.""" for value in ( { CONF_UNIT_SYSTEM: "K" }, { "time_zone": "non-exist" }, { "latitude": "91" }, { "longitude": -181 }, { "customize": "bla" }, { "customize": { "light.sensor": 100 } }, { "customize": { "entity_id": [] } }, ): with pytest.raises(MultipleInvalid): config_util.CORE_CONFIG_SCHEMA(value) config_util.CORE_CONFIG_SCHEMA({ "name": "Test name", "latitude": "-23.45", "longitude": "123.45", CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_METRIC, "customize": { "sensor.temperature": { "hidden": True } }, })
def test_customize_glob_is_ordered(): """Test that customize_glob preserves order.""" conf = config_util.CORE_CONFIG_SCHEMA( {'customize_glob': OrderedDict()}) assert isinstance(conf['customize_glob'], OrderedDict)
def from_config_dict(config, hass=None, config_dir=None, enable_log=True, verbose=False, daemon=False, skip_pip=False, log_rotate_days=None): """Try to configure Home Assistant from a config dict. Dynamically loads required components and its dependencies. """ if hass is None: hass = core.HomeAssistant() if config_dir is not None: config_dir = os.path.abspath(config_dir) hass.config.config_dir = config_dir mount_local_lib_path(config_dir) core_config = config.get(core.DOMAIN, {}) try: process_ha_core_config(hass, config_util.CORE_CONFIG_SCHEMA( core_config)) except vol.MultipleInvalid as ex: cv.log_exception(_LOGGER, ex, 'homeassistant', core_config) return None process_ha_config_upgrade(hass) if enable_log: enable_logging(hass, verbose, daemon, log_rotate_days) hass.config.skip_pip = skip_pip if skip_pip: _LOGGER.warning('Skipping pip installation of required modules. ' 'This may cause issues.') _ensure_loader_prepared(hass) # Make a copy because we are mutating it. # Convert it to defaultdict so components can always have config dict # Convert values to dictionaries if they are None config = defaultdict( dict, {key: value or {} for key, value in config.items()}) # Filter out the repeating and common config section [homeassistant] components = set(key.split(' ')[0] for key in config.keys() if key != core.DOMAIN) if not core_components.setup(hass, config): _LOGGER.error('Home Assistant core failed to initialize. ' 'Further initialization aborted.') return hass _LOGGER.info('Home Assistant core initialized') # Give event decorators access to HASS event_decorators.HASS = hass service.HASS = hass # Setup the components for domain in loader.load_order_components(components): _setup_component(hass, domain, config) return hass