Skip to content

Commit

Permalink
Merge pull request #2381 from home-assistant/dev
Browse files Browse the repository at this point in the history
0.23
  • Loading branch information
balloob authored Jul 1, 2016
2 parents 4f09279 + c44eefa commit 6bc504b
Show file tree
Hide file tree
Showing 131 changed files with 6,176 additions and 1,188 deletions.
12 changes: 12 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ omit =
homeassistant/components/ecobee.py
homeassistant/components/*/ecobee.py

homeassistant/components/envisalink.py
homeassistant/components/*/envisalink.py

homeassistant/components/insteon_hub.py
homeassistant/components/*/insteon_hub.py

Expand Down Expand Up @@ -81,6 +84,9 @@ omit =
homeassistant/components/netatmo.py
homeassistant/components/*/netatmo.py

homeassistant/components/homematic.py
homeassistant/components/*/homematic.py

homeassistant/components/alarm_control_panel/alarmdotcom.py
homeassistant/components/alarm_control_panel/nx584.py
homeassistant/components/binary_sensor/arest.py
Expand Down Expand Up @@ -111,6 +117,8 @@ omit =
homeassistant/components/downloader.py
homeassistant/components/feedreader.py
homeassistant/components/garage_door/wink.py
homeassistant/components/garage_door/rpi_gpio.py
homeassistant/components/hdmi_cec.py
homeassistant/components/ifttt.py
homeassistant/components/keyboard.py
homeassistant/components/light/blinksticklight.py
Expand All @@ -120,7 +128,9 @@ omit =
homeassistant/components/light/limitlessled.py
homeassistant/components/light/osramlightify.py
homeassistant/components/lirc.py
homeassistant/components/media_player/braviatv.py
homeassistant/components/media_player/cast.py
homeassistant/components/media_player/cmus.py
homeassistant/components/media_player/denon.py
homeassistant/components/media_player/firetv.py
homeassistant/components/media_player/gpmdp.py
Expand Down Expand Up @@ -170,6 +180,7 @@ omit =
homeassistant/components/sensor/efergy.py
homeassistant/components/sensor/eliqonline.py
homeassistant/components/sensor/fitbit.py
homeassistant/components/sensor/fixer.py
homeassistant/components/sensor/forecast.py
homeassistant/components/sensor/glances.py
homeassistant/components/sensor/google_travel_time.py
Expand All @@ -180,6 +191,7 @@ omit =
homeassistant/components/sensor/nzbget.py
homeassistant/components/sensor/onewire.py
homeassistant/components/sensor/openweathermap.py
homeassistant/components/sensor/openexchangerates.py
homeassistant/components/sensor/plex.py
homeassistant/components/sensor/rest.py
homeassistant/components/sensor/sabnzbd.py
Expand Down
3 changes: 3 additions & 0 deletions config/configuration.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ http:
# Set to 1 to enable development mode
# development: 1

frontend:
# enable the frontend

light:
# platform: hue

Expand Down
133 changes: 16 additions & 117 deletions homeassistant/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,23 @@
import logging
import logging.handlers
import os
import shutil
import sys
from collections import defaultdict
from threading import RLock

import voluptuous as vol

import homeassistant.components as core_components
import homeassistant.components.group as group
import homeassistant.config as config_util
from homeassistant.components import group, persistent_notification
import homeassistant.config as conf_util
import homeassistant.core as core
import homeassistant.helpers.config_validation as cv
import homeassistant.loader as loader
import homeassistant.util.dt as date_util
import homeassistant.util.location as loc_util
import homeassistant.util.package as pkg_util
from homeassistant.const import (
CONF_CUSTOMIZE, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME,
CONF_TEMPERATURE_UNIT, CONF_TIME_ZONE, EVENT_COMPONENT_LOADED,
TEMP_CELSIUS, TEMP_FAHRENHEIT, PLATFORM_FORMAT, __version__)
from homeassistant.const import EVENT_COMPONENT_LOADED, PLATFORM_FORMAT
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import (
event_decorators, service, config_per_platform, extract_domain_configs)
from homeassistant.helpers.entity import Entity

_LOGGER = logging.getLogger(__name__)
_SETUP_LOCK = RLock()
Expand Down Expand Up @@ -208,11 +201,6 @@ def prepare_setup_platform(hass, config, domain, platform_name):
return platform


def mount_local_lib_path(config_dir):
"""Add local library to Python Path."""
sys.path.insert(0, os.path.join(config_dir, 'deps'))


# pylint: disable=too-many-branches, too-many-statements, too-many-arguments
def from_config_dict(config, hass=None, config_dir=None, enable_log=True,
verbose=False, skip_pip=False,
Expand All @@ -226,18 +214,17 @@ def from_config_dict(config, hass=None, config_dir=None, enable_log=True,
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)
_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:
conf_util.process_ha_core_config(hass, core_config)
except vol.Invalid as ex:
cv.log_exception(_LOGGER, ex, 'homeassistant', core_config)
return None

process_ha_config_upgrade(hass)
conf_util.process_ha_config_upgrade(hass)

if enable_log:
enable_logging(hass, verbose, log_rotate_days)
Expand All @@ -262,9 +249,10 @@ def from_config_dict(config, hass=None, config_dir=None, enable_log=True,
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
Expand All @@ -291,12 +279,12 @@ def from_config_file(config_path, hass=None, verbose=False, skip_pip=True,
# Set config dir to directory holding config file
config_dir = os.path.abspath(os.path.dirname(config_path))
hass.config.config_dir = config_dir
mount_local_lib_path(config_dir)
_mount_local_lib_path(config_dir)

enable_logging(hass, verbose, log_rotate_days)

try:
config_dict = config_util.load_yaml_config_file(config_path)
config_dict = conf_util.load_yaml_config_file(config_path)
except HomeAssistantError:
return None

Expand Down Expand Up @@ -355,101 +343,12 @@ def enable_logging(hass, verbose=False, log_rotate_days=None):
'Unable to setup error log %s (access denied)', err_log_path)


def process_ha_config_upgrade(hass):
"""Upgrade config if necessary."""
version_path = hass.config.path('.HA_VERSION')

try:
with open(version_path, 'rt') as inp:
conf_version = inp.readline().strip()
except FileNotFoundError:
# Last version to not have this file
conf_version = '0.7.7'

if conf_version == __version__:
return

_LOGGER.info('Upgrading config directory from %s to %s', conf_version,
__version__)

# This was where dependencies were installed before v0.18
# Probably should keep this around until ~v0.20.
lib_path = hass.config.path('lib')
if os.path.isdir(lib_path):
shutil.rmtree(lib_path)

lib_path = hass.config.path('deps')
if os.path.isdir(lib_path):
shutil.rmtree(lib_path)

with open(version_path, 'wt') as outp:
outp.write(__version__)


def process_ha_core_config(hass, config):
"""Process the [homeassistant] section from the config."""
hac = hass.config

def set_time_zone(time_zone_str):
"""Helper method to set time zone."""
if time_zone_str is None:
return

time_zone = date_util.get_time_zone(time_zone_str)

if time_zone:
hac.time_zone = time_zone
date_util.set_default_time_zone(time_zone)
else:
_LOGGER.error('Received invalid time zone %s', time_zone_str)

for key, attr in ((CONF_LATITUDE, 'latitude'),
(CONF_LONGITUDE, 'longitude'),
(CONF_NAME, 'location_name')):
if key in config:
setattr(hac, attr, config[key])

if CONF_TIME_ZONE in config:
set_time_zone(config.get(CONF_TIME_ZONE))

for entity_id, attrs in config.get(CONF_CUSTOMIZE).items():
Entity.overwrite_attribute(entity_id, attrs.keys(), attrs.values())

if CONF_TEMPERATURE_UNIT in config:
hac.temperature_unit = config[CONF_TEMPERATURE_UNIT]

# If we miss some of the needed values, auto detect them
if None not in (
hac.latitude, hac.longitude, hac.temperature_unit, hac.time_zone):
return

_LOGGER.warning('Incomplete core config. Auto detecting location and '
'temperature unit')

info = loc_util.detect_location_info()

if info is None:
_LOGGER.error('Could not detect location information')
return

if hac.latitude is None and hac.longitude is None:
hac.latitude = info.latitude
hac.longitude = info.longitude

if hac.temperature_unit is None:
if info.use_fahrenheit:
hac.temperature_unit = TEMP_FAHRENHEIT
else:
hac.temperature_unit = TEMP_CELSIUS

if hac.location_name is None:
hac.location_name = info.city

if hac.time_zone is None:
set_time_zone(info.time_zone)


def _ensure_loader_prepared(hass):
"""Ensure Home Assistant loader is prepared."""
if not loader.PREPARED:
loader.prepare(hass)


def _mount_local_lib_path(config_dir):
"""Add local library to Python Path."""
sys.path.insert(0, os.path.join(config_dir, 'deps'))
24 changes: 24 additions & 0 deletions homeassistant/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

_LOGGER = logging.getLogger(__name__)

SERVICE_RELOAD_CORE_CONFIG = 'reload_core_config'


def is_on(hass, entity_id=None):
"""Load up the module to call the is_on method.
Expand Down Expand Up @@ -73,6 +75,11 @@ def toggle(hass, entity_id=None, **service_data):
hass.services.call(ha.DOMAIN, SERVICE_TOGGLE, service_data)


def reload_core_config(hass):
"""Reload the core config."""
hass.services.call(ha.DOMAIN, SERVICE_RELOAD_CORE_CONFIG)


def setup(hass, config):
"""Setup general services related to Home Assistant."""
def handle_turn_service(service):
Expand Down Expand Up @@ -111,4 +118,21 @@ def handle_turn_service(service):
hass.services.register(ha.DOMAIN, SERVICE_TURN_ON, handle_turn_service)
hass.services.register(ha.DOMAIN, SERVICE_TOGGLE, handle_turn_service)

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 {})

hass.services.register(ha.DOMAIN, SERVICE_RELOAD_CORE_CONFIG,
handle_reload_config)

return True
Loading

0 comments on commit 6bc504b

Please sign in to comment.