Update docstrings (#8536)

This commit is contained in:
Fabian Affolter 2017-07-18 16:23:57 +02:00 committed by GitHub
parent 4ae11c009d
commit 879c816f5c
2 changed files with 46 additions and 46 deletions

View File

@ -40,7 +40,7 @@ def from_config_dict(config: Dict[str, Any],
skip_pip: bool=False, skip_pip: bool=False,
log_rotate_days: Any=None) \ log_rotate_days: Any=None) \
-> Optional[core.HomeAssistant]: -> Optional[core.HomeAssistant]:
"""Try to configure Home Assistant from a config dict. """Try to configure Home Assistant from a configuration dictionary.
Dynamically loads required components and its dependencies. Dynamically loads required components and its dependencies.
""" """
@ -71,7 +71,7 @@ def async_from_config_dict(config: Dict[str, Any],
skip_pip: bool=False, skip_pip: bool=False,
log_rotate_days: Any=None) \ log_rotate_days: Any=None) \
-> Optional[core.HomeAssistant]: -> Optional[core.HomeAssistant]:
"""Try to configure Home Assistant from a config dict. """Try to configure Home Assistant from a configuration dictionary.
Dynamically loads required components and its dependencies. Dynamically loads required components and its dependencies.
This method is a coroutine. This method is a coroutine.
@ -92,8 +92,8 @@ def async_from_config_dict(config: Dict[str, Any],
hass.config.skip_pip = skip_pip hass.config.skip_pip = skip_pip
if skip_pip: if skip_pip:
_LOGGER.warning('Skipping pip installation of required modules. ' _LOGGER.warning("Skipping pip installation of required modules. "
'This may cause issues.') "This may cause issues")
if not loader.PREPARED: if not loader.PREPARED:
yield from hass.async_add_job(loader.prepare, hass) yield from hass.async_add_job(loader.prepare, hass)
@ -118,13 +118,13 @@ def async_from_config_dict(config: Dict[str, Any],
# pylint: disable=not-an-iterable # pylint: disable=not-an-iterable
res = yield from core_components.async_setup(hass, config) res = yield from core_components.async_setup(hass, config)
if not res: if not res:
_LOGGER.error('Home Assistant core failed to initialize. ' _LOGGER.error("Home Assistant core failed to initialize. "
'Further initialization aborted.') "further initialization aborted")
return hass return hass
yield from persistent_notification.async_setup(hass, config) yield from persistent_notification.async_setup(hass, config)
_LOGGER.info('Home Assistant core initialized') _LOGGER.info("Home Assistant core initialized")
# stage 1 # stage 1
for component in components: for component in components:
@ -143,7 +143,7 @@ def async_from_config_dict(config: Dict[str, Any],
yield from hass.async_block_till_done() yield from hass.async_block_till_done()
stop = time() stop = time()
_LOGGER.info('Home Assistant initialized in %.2fs', stop-start) _LOGGER.info("Home Assistant initialized in %.2fs", stop-start)
async_register_signal_handling(hass) async_register_signal_handling(hass)
return hass return hass
@ -193,7 +193,7 @@ def async_from_config_file(config_path: str,
config_dict = yield from hass.async_add_job( config_dict = yield from hass.async_add_job(
conf_util.load_yaml_config_file, config_path) conf_util.load_yaml_config_file, config_path)
except HomeAssistantError as err: except HomeAssistantError as err:
_LOGGER.error('Error loading %s: %s', config_path, err) _LOGGER.error("Error loading %s: %s", config_path, err)
return None return None
finally: finally:
clear_secret_cache() clear_secret_cache()

View File

@ -40,7 +40,7 @@ CONFIG_DIR_NAME = '.homeassistant'
DATA_CUSTOMIZE = 'hass_customize' DATA_CUSTOMIZE = 'hass_customize'
FILE_MIGRATION = [ FILE_MIGRATION = [
["ios.conf", ".ios.conf"], ['ios.conf', '.ios.conf'],
] ]
DEFAULT_CORE_CONFIG = ( DEFAULT_CORE_CONFIG = (
@ -71,7 +71,7 @@ config:
http: http:
# Uncomment this to add a password (recommended!) # Uncomment this to add a password (recommended!)
# api_password: PASSWORD # api_password: PASSWORD
# Uncomment this if you are using SSL or running in Docker etc # Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# base_url: example.duckdns.org:8123 # base_url: example.duckdns.org:8123
# Checks for available updates # Checks for available updates
@ -89,7 +89,7 @@ discovery:
# Allows you to issue voice commands from the frontend in enabled browsers # Allows you to issue voice commands from the frontend in enabled browsers
conversation: conversation:
# Enables support for tracking state changes over time. # Enables support for tracking state changes over time
history: history:
# View all events in a logbook # View all events in a logbook
@ -98,13 +98,13 @@ logbook:
# Track the sun # Track the sun
sun: sun:
# Weather Prediction # Weather prediction
sensor: sensor:
platform: yr - platform: yr
# Text to speech # Text to speech
tts: tts:
platform: google - platform: google
group: !include groups.yaml group: !include groups.yaml
automation: !include automations.yaml automation: !include automations.yaml
@ -141,17 +141,17 @@ CORE_CONFIG_SCHEMA = CUSTOMIZE_CONFIG_SCHEMA.extend({
def get_default_config_dir() -> str: def get_default_config_dir() -> str:
"""Put together the default configuration directory based on OS.""" """Put together the default configuration directory based on the OS."""
data_dir = os.getenv('APPDATA') if os.name == "nt" \ data_dir = os.getenv('APPDATA') if os.name == "nt" \
else os.path.expanduser('~') else os.path.expanduser('~')
return os.path.join(data_dir, CONFIG_DIR_NAME) return os.path.join(data_dir, CONFIG_DIR_NAME)
def ensure_config_exists(config_dir: str, detect_location: bool=True) -> str: def ensure_config_exists(config_dir: str, detect_location: bool=True) -> str:
"""Ensure a config file exists in given configuration directory. """Ensure a configuration file exists in given configuration directory.
Creating a default one if needed. Creating a default one if needed.
Return path to the config file. Return path to the configuration file.
""" """
config_path = find_config_file(config_dir) config_path = find_config_file(config_dir)
@ -195,8 +195,8 @@ def create_default_config(config_dir, detect_location=True):
info[attr] = getattr(location_info, prop) or default info[attr] = getattr(location_info, prop) or default
if location_info.latitude and location_info.longitude: if location_info.latitude and location_info.longitude:
info[CONF_ELEVATION] = loc_util.elevation(location_info.latitude, info[CONF_ELEVATION] = loc_util.elevation(
location_info.longitude) location_info.latitude, location_info.longitude)
# Writing files with YAML does not create the most human readable results # Writing files with YAML does not create the most human readable results
# So we're hard coding a YAML template. # So we're hard coding a YAML template.
@ -225,16 +225,16 @@ def create_default_config(config_dir, detect_location=True):
return config_path return config_path
except IOError: except IOError:
print('Unable to create default configuration file', config_path) print("Unable to create default configuration file", config_path)
return None return None
@asyncio.coroutine @asyncio.coroutine
def async_hass_config_yaml(hass): def async_hass_config_yaml(hass):
"""Load YAML from hass config File. """Load YAML from a Home Assistant configuration file.
This function allow component inside asyncio loop to reload his config by This function allow a component inside the asyncio loop to reload its
self. configuration by itself.
This method is a coroutine. This method is a coroutine.
""" """
@ -269,7 +269,7 @@ def load_yaml_config_file(config_path):
getattr(err, 'filename', err))) getattr(err, 'filename', err)))
if not isinstance(conf_dict, dict): if not isinstance(conf_dict, dict):
msg = 'The configuration file {} does not contain a dictionary'.format( msg = "The configuration file {} does not contain a dictionary".format(
os.path.basename(config_path)) os.path.basename(config_path))
_LOGGER.error(msg) _LOGGER.error(msg)
raise HomeAssistantError(msg) raise HomeAssistantError(msg)
@ -278,7 +278,7 @@ def load_yaml_config_file(config_path):
def process_ha_config_upgrade(hass): def process_ha_config_upgrade(hass):
"""Upgrade config if necessary. """Upgrade configuration if necessary.
This method needs to run in an executor. This method needs to run in an executor.
""" """
@ -294,8 +294,8 @@ def process_ha_config_upgrade(hass):
if conf_version == __version__: if conf_version == __version__:
return return
_LOGGER.info('Upgrading config directory from %s to %s', conf_version, _LOGGER.info("Upgrading configuration directory from %s to %s",
__version__) conf_version, __version__)
if LooseVersion(conf_version) < LooseVersion('0.49'): if LooseVersion(conf_version) < LooseVersion('0.49'):
# 0.49 introduced persistent deps dir. # 0.49 introduced persistent deps dir.
@ -306,20 +306,20 @@ def process_ha_config_upgrade(hass):
with open(version_path, 'wt') as outp: with open(version_path, 'wt') as outp:
outp.write(__version__) outp.write(__version__)
_LOGGER.info('Migrating old system config files to new locations') _LOGGER.info("Migrating old system configuration files to new locations")
for oldf, newf in FILE_MIGRATION: for oldf, newf in FILE_MIGRATION:
if os.path.isfile(hass.config.path(oldf)): if os.path.isfile(hass.config.path(oldf)):
_LOGGER.info('Migrating %s to %s', oldf, newf) _LOGGER.info("Migrating %s to %s", oldf, newf)
os.rename(hass.config.path(oldf), hass.config.path(newf)) os.rename(hass.config.path(oldf), hass.config.path(newf))
@callback @callback
def async_log_exception(ex, domain, config, hass): def async_log_exception(ex, domain, config, hass):
"""Generate log exception for config validation. """Generate log exception for configuration validation.
This method must be run in the event loop. This method must be run in the event loop.
""" """
message = 'Invalid config for [{}]: '.format(domain) message = "Invalid config for [{}]: ".format(domain)
if hass is not None: if hass is not None:
async_notify_setup_error(hass, domain, True) async_notify_setup_error(hass, domain, True)
@ -344,7 +344,7 @@ def async_log_exception(ex, domain, config, hass):
@asyncio.coroutine @asyncio.coroutine
def async_process_ha_core_config(hass, config): def async_process_ha_core_config(hass, config):
"""Process the [homeassistant] section from the config. """Process the [homeassistant] section from the configuration.
This method is a coroutine. This method is a coroutine.
""" """
@ -362,7 +362,7 @@ def async_process_ha_core_config(hass, config):
hac.time_zone = time_zone hac.time_zone = time_zone
date_util.set_default_time_zone(time_zone) date_util.set_default_time_zone(time_zone)
else: else:
_LOGGER.error('Received invalid time zone %s', time_zone_str) _LOGGER.error("Received invalid time zone %s", time_zone_str)
for key, attr in ((CONF_LATITUDE, 'latitude'), for key, attr in ((CONF_LATITUDE, 'latitude'),
(CONF_LONGITUDE, 'longitude'), (CONF_LONGITUDE, 'longitude'),
@ -374,7 +374,7 @@ def async_process_ha_core_config(hass, config):
if CONF_TIME_ZONE in config: if CONF_TIME_ZONE in config:
set_time_zone(config.get(CONF_TIME_ZONE)) set_time_zone(config.get(CONF_TIME_ZONE))
# init whitelist external dir # Init whitelist external dir
hac.whitelist_external_dirs = set((hass.config.path('www'),)) hac.whitelist_external_dirs = set((hass.config.path('www'),))
if CONF_WHITELIST_EXTERNAL_DIRS in config: if CONF_WHITELIST_EXTERNAL_DIRS in config:
hac.whitelist_external_dirs.update( hac.whitelist_external_dirs.update(
@ -394,7 +394,7 @@ def async_process_ha_core_config(hass, config):
try: try:
pkg_cust = CUSTOMIZE_CONFIG_SCHEMA(pkg_cust) pkg_cust = CUSTOMIZE_CONFIG_SCHEMA(pkg_cust)
except vol.Invalid: except vol.Invalid:
_LOGGER.warning('Package %s contains invalid customize', name) _LOGGER.warning("Package %s contains invalid customize", name)
continue continue
cust_exact.update(pkg_cust[CONF_CUSTOMIZE]) cust_exact.update(pkg_cust[CONF_CUSTOMIZE])
@ -415,9 +415,9 @@ def async_process_ha_core_config(hass, config):
hac.units = METRIC_SYSTEM hac.units = METRIC_SYSTEM
else: else:
hac.units = IMPERIAL_SYSTEM hac.units = IMPERIAL_SYSTEM
_LOGGER.warning("Found deprecated temperature unit in core config, " _LOGGER.warning("Found deprecated temperature unit in core "
"expected unit system. Replace '%s: %s' with " "configuration expected unit system. Replace '%s: %s' "
"'%s: %s'", CONF_TEMPERATURE_UNIT, unit, "with '%s: %s'", CONF_TEMPERATURE_UNIT, unit,
CONF_UNIT_SYSTEM, hac.units.name) CONF_UNIT_SYSTEM, hac.units.name)
# Shortcut if no auto-detection necessary # Shortcut if no auto-detection necessary
@ -434,7 +434,7 @@ def async_process_ha_core_config(hass, config):
loc_util.detect_location_info) loc_util.detect_location_info)
if info is None: if info is None:
_LOGGER.error('Could not detect location information') _LOGGER.error("Could not detect location information")
return return
if hac.latitude is None and hac.longitude is None: if hac.latitude is None and hac.longitude is None:
@ -463,8 +463,8 @@ def async_process_ha_core_config(hass, config):
if discovered: if discovered:
_LOGGER.warning( _LOGGER.warning(
'Incomplete core config. Auto detected %s', "Incomplete core configuration. Auto detected %s",
', '.join('{}: {}'.format(key, val) for key, val in discovered)) ", ".join('{}: {}'.format(key, val) for key, val in discovered))
def _log_pkg_error(package, component, config, message): def _log_pkg_error(package, component, config, message):
@ -495,7 +495,7 @@ def _identify_config_schema(module):
def merge_packages_config(config, packages): def merge_packages_config(config, packages):
"""Merge packages into the top-level config. Mutate config.""" """Merge packages into the top-level configuration. Mutate config."""
# pylint: disable=too-many-nested-blocks # pylint: disable=too-many-nested-blocks
PACKAGES_CONFIG_SCHEMA(packages) PACKAGES_CONFIG_SCHEMA(packages)
for pack_name, pack_conf in packages.items(): for pack_name, pack_conf in packages.items():
@ -549,7 +549,7 @@ def merge_packages_config(config, packages):
if comp_name in config: if comp_name in config:
_log_pkg_error( _log_pkg_error(
pack_name, comp_name, config, "may occur only once" pack_name, comp_name, config, "may occur only once"
" and it already exist in your main config") " and it already exist in your main configuration")
continue continue
config[comp_name] = comp_conf config[comp_name] = comp_conf
@ -558,7 +558,7 @@ def merge_packages_config(config, packages):
@callback @callback
def async_process_component_config(hass, config, domain): def async_process_component_config(hass, config, domain):
"""Check component config and return processed config. """Check component configuration and return processed configuration.
Raise a vol.Invalid exception on error. Raise a vol.Invalid exception on error.
@ -619,7 +619,7 @@ def async_process_component_config(hass, config, domain):
@asyncio.coroutine @asyncio.coroutine
def async_check_ha_config_file(hass): def async_check_ha_config_file(hass):
"""Check if HA config file valid. """Check if Home Assistant configuration file is valid.
This method is a coroutine. This method is a coroutine.
""" """