def test_entity_customization(self): """Test entity customization through configuration.""" self.hass = get_test_home_assistant() config = { CONF_LATITUDE: 50, CONF_LONGITUDE: 50, CONF_NAME: 'Test', CONF_CUSTOMIZE: { 'test.test': { 'hidden': True } } } config_util.process_ha_core_config(self.hass, config) entity = Entity() entity.entity_id = 'test.test' entity.hass = self.hass entity.update_ha_state() self.hass.block_till_done() state = self.hass.states.get('test.test') assert state.attributes['hidden']
def handle_reload_config(call): """Service handler for reloading core config.""" from homeassistant.exceptions import HomeAssistantError from homeassistant import config as conf_util try: path = conf_util.find_config_file(hass.config.config_dir) conf = conf_util.load_yaml_config_file(path) except HomeAssistantError as err: _LOGGER.error(err) return conf_util.process_ha_core_config(hass, conf.get(ha.DOMAIN) or {})
def handle_reload_config(call): """Service handler for reloading core config.""" from homeassistant.exceptions import HomeAssistantError from homeassistant import config as conf_util try: path = conf_util.find_config_file(hass.config.config_dir) conf = conf_util.load_yaml_config_file(path) except HomeAssistantError as err: _LOGGER.error(err) return conf_util.process_ha_core_config(hass, conf.get(ha.DOMAIN) or {})
def test_discovering_configuration(self, mock_detect, mock_elevation): """Test auto discovery for missing core configs.""" config = Config() hass = mock.Mock(config=config) config_util.process_ha_core_config(hass, {}) assert config.latitude == 32.8594 assert config.longitude == -117.2073 assert config.elevation == 101 assert config.location_name == 'San Diego' assert config.temperature_unit == TEMP_FAHRENHEIT assert config.time_zone.zone == 'America/Los_Angeles'
def test_discovering_configuration(self, mock_detect, mock_elevation): """Test auto discovery for missing core configs.""" config = Config() hass = mock.Mock(config=config) config_util.process_ha_core_config(hass, {}) assert config.latitude == 32.8594 assert config.longitude == -117.2073 assert config.elevation == 101 assert config.location_name == 'San Diego' assert config.units.name == CONF_UNIT_SYSTEM_METRIC assert config.units.is_metric assert config.time_zone.zone == 'America/Los_Angeles'
def test_discovering_configuration(self, mock_detect, mock_elevation): """Test auto discovery for missing core configs.""" config = Config() hass = mock.Mock(config=config) config_util.process_ha_core_config(hass, {}) assert config.latitude == 32.8594 assert config.longitude == -117.2073 assert config.elevation == 101 assert config.location_name == 'San Diego' assert config.units.name == CONF_UNIT_SYSTEM_METRIC assert config.units.is_metric assert config.time_zone.zone == 'America/Los_Angeles'
def test_discovering_configuration_auto_detect_fails(self, mock_detect, mock_elevation): """Test config remains unchanged if discovery fails.""" config = Config() hass = mock.Mock(config=config) config_util.process_ha_core_config(hass, {}) blankConfig = Config() assert config.latitude == blankConfig.latitude assert config.longitude == blankConfig.longitude assert config.elevation == blankConfig.elevation assert config.location_name == blankConfig.location_name assert config.units == blankConfig.units assert config.time_zone == blankConfig.time_zone
def test_discovering_configuration_auto_detect_fails( self, mock_detect, mock_elevation): """Test config remains unchanged if discovery fails.""" config = Config() hass = mock.Mock(config=config) config_util.process_ha_core_config(hass, {}) blankConfig = Config() assert config.latitude == blankConfig.latitude assert config.longitude == blankConfig.longitude assert config.elevation == blankConfig.elevation assert config.location_name == blankConfig.location_name assert config.units == blankConfig.units assert config.time_zone == blankConfig.time_zone
def test_entity_customization(self): """Test entity customization through configuration.""" self.hass = get_test_home_assistant() config = {CONF_LATITUDE: 50, CONF_LONGITUDE: 50, CONF_NAME: 'Test', CONF_CUSTOMIZE: {'test.test': {'hidden': True}}} config_util.process_ha_core_config(self.hass, config) entity = Entity() entity.entity_id = 'test.test' entity.hass = self.hass entity.update_ha_state() state = self.hass.states.get('test.test') assert state.attributes['hidden']
def test_loading_configuration_temperature_unit(self): """Test backward compatibility when loading core config.""" config = Config() hass = mock.Mock(config=config) config_util.process_ha_core_config(hass, { 'latitude': 60, 'longitude': 50, 'elevation': 25, 'name': 'Huis', CONF_TEMPERATURE_UNIT: 'C', 'time_zone': 'America/New_York', }) assert config.latitude == 60 assert config.longitude == 50 assert config.elevation == 25 assert config.location_name == 'Huis' assert config.units.name == CONF_UNIT_SYSTEM_METRIC assert config.time_zone.zone == 'America/New_York'
def test_loading_configuration(self): """Test loading core config onto hass object.""" config = Config() hass = mock.Mock(config=config) config_util.process_ha_core_config(hass, { 'latitude': 60, 'longitude': 50, 'elevation': 25, 'name': 'Huis', CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_IMPERIAL, 'time_zone': 'America/New_York', }) assert config.latitude == 60 assert config.longitude == 50 assert config.elevation == 25 assert config.location_name == 'Huis' assert config.units.name == CONF_UNIT_SYSTEM_IMPERIAL assert config.time_zone.zone == 'America/New_York'
def test_loading_configuration(self): """Test loading core config onto hass object.""" config = Config() hass = mock.Mock(config=config) config_util.process_ha_core_config(hass, { 'latitude': 60, 'longitude': 50, 'elevation': 25, 'name': 'Huis', 'temperature_unit': 'F', 'time_zone': 'America/New_York', }) assert config.latitude == 60 assert config.longitude == 50 assert config.elevation == 25 assert config.location_name == 'Huis' assert config.temperature_unit == TEMP_FAHRENHEIT assert config.time_zone.zone == 'America/New_York'
def test_loading_configuration_temperature_unit(self): """Test backward compatibility when loading core config.""" config = Config() hass = mock.Mock(config=config) config_util.process_ha_core_config( hass, { 'latitude': 60, 'longitude': 50, 'elevation': 25, 'name': 'Huis', CONF_TEMPERATURE_UNIT: 'C', 'time_zone': 'America/New_York', }) assert config.latitude == 60 assert config.longitude == 50 assert config.elevation == 25 assert config.location_name == 'Huis' assert config.units.name == CONF_UNIT_SYSTEM_METRIC assert config.time_zone.zone == 'America/New_York'
def test_loading_configuration(self): """Test loading core config onto hass object.""" config = Config() hass = mock.Mock(config=config) config_util.process_ha_core_config( hass, { 'latitude': 60, 'longitude': 50, 'elevation': 25, 'name': 'Huis', CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_IMPERIAL, 'time_zone': 'America/New_York', }) assert config.latitude == 60 assert config.longitude == 50 assert config.elevation == 25 assert config.location_name == 'Huis' assert config.units.name == CONF_UNIT_SYSTEM_IMPERIAL assert config.time_zone.zone == 'America/New_York'
def from_config_dict(config, hass=None, config_dir=None, enable_log=True, verbose=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: conf_util.process_ha_core_config(hass, core_config) except vol.Invalid as ex: cv.log_exception(_LOGGER, ex, 'homeassistant', core_config) return None conf_util.process_ha_config_upgrade(hass) if enable_log: enable_logging(hass, verbose, 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 persistent_notification.setup(hass, config) _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
def from_config_dict(config: Dict[str, Any], hass: Optional[core.HomeAssistant]=None, config_dir: Optional[str]=None, enable_log: bool=True, verbose: bool=False, skip_pip: bool=False, log_rotate_days: Any=None) \ -> Optional[core.HomeAssistant]: """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: conf_util.process_ha_core_config(hass, core_config) except vol.Invalid as ex: _log_exception(ex, 'homeassistant', core_config) return None conf_util.process_ha_config_upgrade(hass) if enable_log: enable_logging(hass, verbose, 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 persistent_notification.setup(hass, config) _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