Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions homeassistant/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import voluptuous as vol

from homeassistant import (
core, config as conf_util, config_entries, loader,
components as core_components)
core, config as conf_util, config_entries, components as core_components)
from homeassistant.components import persistent_notification
from homeassistant.const import EVENT_HOMEASSISTANT_CLOSE
from homeassistant.setup import async_setup_component
Expand Down Expand Up @@ -103,15 +102,12 @@ async def async_from_config_dict(config: Dict[str, Any],
_LOGGER.warning("Skipping pip installation of required modules. "
"This may cause issues")

if not loader.PREPARED:
await hass.async_add_job(loader.prepare, hass)

# Make a copy because we are mutating it.
config = OrderedDict(config)

# Merge packages
conf_util.merge_packages_config(
config, core_config.get(conf_util.CONF_PACKAGES, {}))
hass, config, core_config.get(conf_util.CONF_PACKAGES, {}))

# Ensure we have no None values after merge
for key, value in config.items():
Expand Down
16 changes: 9 additions & 7 deletions homeassistant/components/automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
import asyncio
from functools import partial
import importlib
import logging

import voluptuous as vol
Expand All @@ -22,7 +23,6 @@
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import async_get_last_state
from homeassistant.loader import get_platform
from homeassistant.util.dt import utcnow
import homeassistant.helpers.config_validation as cv

Expand Down Expand Up @@ -58,20 +58,22 @@

def _platform_validator(config):
"""Validate it is a valid platform."""
platform = get_platform(DOMAIN, config[CONF_PLATFORM])
try:
platform = importlib.import_module(
'homeassistant.components.automation.{}'.format(
config[CONF_PLATFORM]))
except ImportError:
raise vol.Invalid('Invalid platform specified') from None

if not hasattr(platform, 'TRIGGER_SCHEMA'):
return config

return getattr(platform, 'TRIGGER_SCHEMA')(config)
return platform.TRIGGER_SCHEMA(config)


_TRIGGER_SCHEMA = vol.All(
cv.ensure_list,
[
vol.All(
vol.Schema({
vol.Required(CONF_PLATFORM): cv.platform_validator(DOMAIN)
vol.Required(CONF_PLATFORM): str
}, extra=vol.ALLOW_EXTRA),
_platform_validator
),
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/binary_sensor/bloomsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from homeassistant.components.binary_sensor import (
BinarySensorDevice, PLATFORM_SCHEMA)
from homeassistant.const import CONF_MONITORED_CONDITIONS
from homeassistant.loader import get_component
import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)
Expand All @@ -31,7 +30,7 @@

def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the available BloomSky weather binary sensors."""
bloomsky = get_component('bloomsky')
bloomsky = hass.components.bloomsky
# Default needed in case of discovery
sensors = config.get(CONF_MONITORED_CONDITIONS, SENSOR_TYPES)

Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/binary_sensor/netatmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from homeassistant.components.binary_sensor import (
BinarySensorDevice, PLATFORM_SCHEMA)
from homeassistant.components.netatmo import CameraData
from homeassistant.loader import get_component
from homeassistant.const import CONF_TIMEOUT
from homeassistant.helpers import config_validation as cv

Expand Down Expand Up @@ -61,7 +60,7 @@
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the access to Netatmo binary sensor."""
netatmo = get_component('netatmo')
netatmo = hass.components.netatmo
home = config.get(CONF_HOME)
timeout = config.get(CONF_TIMEOUT)
if timeout is None:
Expand Down
7 changes: 3 additions & 4 deletions homeassistant/components/binary_sensor/wemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import logging

from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.loader import get_component

DEPENDENCIES = ['wemo']

Expand All @@ -25,18 +24,18 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
device = discovery.device_from_description(location, mac)

if device:
add_devices_callback([WemoBinarySensor(device)])
add_devices_callback([WemoBinarySensor(hass, device)])


class WemoBinarySensor(BinarySensorDevice):
"""Representation a WeMo binary sensor."""

def __init__(self, device):
def __init__(self, hass, device):
"""Initialize the WeMo sensor."""
self.wemo = device
self._state = None

wemo = get_component('wemo')
wemo = hass.components.wemo
wemo.SUBSCRIPTION_REGISTRY.register(self.wemo)
wemo.SUBSCRIPTION_REGISTRY.on(self.wemo, None, self._update_callback)

Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/camera/bloomsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import requests

from homeassistant.components.camera import Camera
from homeassistant.loader import get_component

DEPENDENCIES = ['bloomsky']


# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up access to BloomSky cameras."""
bloomsky = get_component('bloomsky')
bloomsky = hass.components.bloomsky
for device in bloomsky.BLOOMSKY.devices.values():
add_devices([BloomSkyCamera(bloomsky.BLOOMSKY, device)])

Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/camera/netatmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from homeassistant.const import CONF_VERIFY_SSL
from homeassistant.components.netatmo import CameraData
from homeassistant.components.camera import (Camera, PLATFORM_SCHEMA)
from homeassistant.loader import get_component
from homeassistant.helpers import config_validation as cv

DEPENDENCIES = ['netatmo']
Expand All @@ -33,7 +32,7 @@
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up access to Netatmo cameras."""
netatmo = get_component('netatmo')
netatmo = hass.components.netatmo
home = config.get(CONF_HOME)
verify_ssl = config.get(CONF_VERIFY_SSL, True)
import lnetatmo
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/climate/netatmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
STATE_HEAT, STATE_IDLE, ClimateDevice, PLATFORM_SCHEMA,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_OPERATION_MODE, SUPPORT_AWAY_MODE)
from homeassistant.util import Throttle
from homeassistant.loader import get_component
import homeassistant.helpers.config_validation as cv

DEPENDENCIES = ['netatmo']
Expand Down Expand Up @@ -42,7 +41,7 @@

def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the NetAtmo Thermostat."""
netatmo = get_component('netatmo')
netatmo = hass.components.netatmo
device = config.get(CONF_RELAY)

import lnetatmo
Expand Down
25 changes: 12 additions & 13 deletions homeassistant/components/device_sun_light_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from homeassistant.helpers.event import (
async_track_point_in_utc_time, async_track_state_change)
from homeassistant.helpers.sun import is_up, get_astral_event_next
from homeassistant.loader import get_component
import homeassistant.helpers.config_validation as cv

DOMAIN = 'device_sun_light_trigger'
Expand Down Expand Up @@ -48,24 +47,24 @@
def async_setup(hass, config):
"""Set up the triggers to control lights based on device presence."""
logger = logging.getLogger(__name__)
device_tracker = get_component('device_tracker')
group = get_component('group')
light = get_component('light')
device_tracker = hass.components.device_tracker
group = hass.components.group
light = hass.components.light
conf = config[DOMAIN]
disable_turn_off = conf.get(CONF_DISABLE_TURN_OFF)
light_group = conf.get(CONF_LIGHT_GROUP, light.ENTITY_ID_ALL_LIGHTS)
light_profile = conf.get(CONF_LIGHT_PROFILE)
device_group = conf.get(
CONF_DEVICE_GROUP, device_tracker.ENTITY_ID_ALL_DEVICES)
device_entity_ids = group.get_entity_ids(
hass, device_group, device_tracker.DOMAIN)
device_group, device_tracker.DOMAIN)

if not device_entity_ids:
logger.error("No devices found to track")
return False

# Get the light IDs from the specified group
light_ids = group.get_entity_ids(hass, light_group, light.DOMAIN)
light_ids = group.get_entity_ids(light_group, light.DOMAIN)

if not light_ids:
logger.error("No lights found to turn on")
Expand All @@ -85,9 +84,9 @@ def calc_time_for_light_when_sunset():

def async_turn_on_before_sunset(light_id):
"""Turn on lights."""
if not device_tracker.is_on(hass) or light.is_on(hass, light_id):
if not device_tracker.is_on() or light.is_on(light_id):
return
light.async_turn_on(hass, light_id,
light.async_turn_on(light_id,
transition=LIGHT_TRANSITION_TIME.seconds,
profile=light_profile)

Expand Down Expand Up @@ -129,7 +128,7 @@ def schedule_light_turn_on(now):
@callback
def check_light_on_dev_state_change(entity, old_state, new_state):
"""Handle tracked device state changes."""
lights_are_on = group.is_on(hass, light_group)
lights_are_on = group.is_on(light_group)
light_needed = not (lights_are_on or is_up(hass))

# These variables are needed for the elif check
Expand All @@ -139,7 +138,7 @@ def check_light_on_dev_state_change(entity, old_state, new_state):
# Do we need lights?
if light_needed:
logger.info("Home coming event for %s. Turning lights on", entity)
light.async_turn_on(hass, light_ids, profile=light_profile)
light.async_turn_on(light_ids, profile=light_profile)

# Are we in the time span were we would turn on the lights
# if someone would be home?
Expand All @@ -152,7 +151,7 @@ def check_light_on_dev_state_change(entity, old_state, new_state):
# when the fading in started and turn it on if so
for index, light_id in enumerate(light_ids):
if now > start_point + index * LIGHT_TRANSITION_TIME:
light.async_turn_on(hass, light_id)
light.async_turn_on(light_id)

else:
# If this light didn't happen to be turned on yet so
Expand All @@ -169,12 +168,12 @@ def check_light_on_dev_state_change(entity, old_state, new_state):
@callback
def turn_off_lights_when_all_leave(entity, old_state, new_state):
"""Handle device group state change."""
if not group.is_on(hass, light_group):
if not group.is_on(light_group):
return

logger.info(
"Everyone has left but there are lights on. Turning them off")
light.async_turn_off(hass, light_ids)
light.async_turn_off(light_ids)

async_track_state_change(
hass, device_group, turn_off_lights_when_all_leave,
Expand Down
7 changes: 3 additions & 4 deletions homeassistant/components/device_tracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from homeassistant.helpers.restore_state import async_get_last_state
from homeassistant.helpers.typing import GPSType, ConfigType, HomeAssistantType
import homeassistant.helpers.config_validation as cv
from homeassistant.loader import get_component
import homeassistant.util as util
from homeassistant.util.async_ import run_coroutine_threadsafe
import homeassistant.util.dt as dt_util
Expand Down Expand Up @@ -322,7 +321,7 @@ def async_see(
# During init, we ignore the group
if self.group and self.track_new:
self.group.async_set_group(
self.hass, util.slugify(GROUP_NAME_ALL_DEVICES), visible=False,
util.slugify(GROUP_NAME_ALL_DEVICES), visible=False,
name=GROUP_NAME_ALL_DEVICES, add=[device.entity_id])

self.hass.bus.async_fire(EVENT_NEW_DEVICE, {
Expand Down Expand Up @@ -357,9 +356,9 @@ def async_setup_group(self):
entity_ids = [dev.entity_id for dev in self.devices.values()
if dev.track]

self.group = get_component('group')
self.group = self.hass.components.group
self.group.async_set_group(
self.hass, util.slugify(GROUP_NAME_ALL_DEVICES), visible=False,
util.slugify(GROUP_NAME_ALL_DEVICES), visible=False,
name=GROUP_NAME_ALL_DEVICES, entity_ids=entity_ids)

@callback
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/image_processing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from homeassistant.loader import bind_hass
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.loader import get_component

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -121,12 +120,12 @@ def async_update(self):

This method is a coroutine.
"""
camera = get_component('camera')
camera = self.hass.components.camera
image = None

try:
image = yield from camera.async_get_image(
self.hass, self.camera_entity, timeout=self.timeout)
self.camera_entity, timeout=self.timeout)

except HomeAssistantError as err:
_LOGGER.error("Error on receive image from entity: %s", err)
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/light/wemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from homeassistant.components.light import (
Light, ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_HS_COLOR, ATTR_TRANSITION,
SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_COLOR, SUPPORT_TRANSITION)
from homeassistant.loader import get_component
import homeassistant.util.color as color_util

DEPENDENCIES = ['wemo']
Expand Down Expand Up @@ -151,7 +150,7 @@ def __init__(self, device):
@asyncio.coroutine
def async_added_to_hass(self):
"""Register update callback."""
wemo = get_component('wemo')
wemo = self.hass.components.wemo
# The register method uses a threading condition, so call via executor.
# and yield from to wait until the task is done.
yield from self.hass.async_add_job(
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/microsoft_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.loader import get_component
from homeassistant.util import slugify

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -231,7 +230,7 @@ def async_face_person(service):
p_id = face.store[g_id].get(service.data[ATTR_PERSON])

camera_entity = service.data[ATTR_CAMERA_ENTITY]
camera = get_component('camera')
camera = hass.components.camera

try:
image = yield from camera.async_get_image(hass, camera_entity)
Expand Down
7 changes: 3 additions & 4 deletions homeassistant/components/mqtt_eventstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import voluptuous as vol

from homeassistant.core import callback
import homeassistant.loader as loader
from homeassistant.components.mqtt import (
valid_publish_topic, valid_subscribe_topic)
from homeassistant.const import (
Expand Down Expand Up @@ -42,7 +41,7 @@
@asyncio.coroutine
def async_setup(hass, config):
"""Set up the MQTT eventstream component."""
mqtt = loader.get_component('mqtt')
mqtt = hass.components.mqtt
conf = config.get(DOMAIN, {})
pub_topic = conf.get(CONF_PUBLISH_TOPIC)
sub_topic = conf.get(CONF_SUBSCRIBE_TOPIC)
Expand Down Expand Up @@ -82,7 +81,7 @@ def _event_publisher(event):

event_info = {'event_type': event.event_type, 'event_data': event.data}
msg = json.dumps(event_info, cls=JSONEncoder)
mqtt.async_publish(hass, pub_topic, msg)
mqtt.async_publish(pub_topic, msg)

# Only listen for local events if you are going to publish them.
if pub_topic:
Expand Down Expand Up @@ -115,7 +114,7 @@ def _event_receiver(topic, payload, qos):

# Only subscribe if you specified a topic.
if sub_topic:
yield from mqtt.async_subscribe(hass, sub_topic, _event_receiver)
yield from mqtt.async_subscribe(sub_topic, _event_receiver)

hass.states.async_set('{domain}.initialized'.format(domain=DOMAIN), True)
return True
Loading