From 7e9a254d878007c9905227cdc9f242b4533c32c6 Mon Sep 17 00:00:00 2001 From: Gustav Ahlberg Date: Mon, 2 Feb 2015 07:30:46 +0100 Subject: [PATCH] Make sure that components isn't loaded multiple times --- .../components/scheduler/__init__.py | 21 ++++++++++++++----- homeassistant/components/sun.py | 2 -- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/scheduler/__init__.py b/homeassistant/components/scheduler/__init__.py index 29a09c25fb0..d77b3e916b0 100644 --- a/homeassistant/components/scheduler/__init__.py +++ b/homeassistant/components/scheduler/__init__.py @@ -18,14 +18,14 @@ entity_ids, and events. import logging import json +from homeassistant import bootstrap from homeassistant.loader import get_component - from homeassistant.const import ATTR_ENTITY_ID # The domain of your component. Should be equal to the name of your component DOMAIN = 'scheduler' -DEPENDENCIES = ['sun'] +DEPENDENCIES = [] _LOGGER = logging.getLogger(__name__) @@ -36,13 +36,22 @@ _SCHEDULE_FILE = 'schedule.json' def setup(hass, config): """ Create the schedules """ + if DOMAIN in hass.components: + return True + def setup_listener(schedule, event_data): - type = event_data['type'] + event_type = event_data['type'] component = type - if type in ('time'): + if event_type in ('time'): component = 'scheduler.{}'.format(type) + elif component not in hass.components and \ + not bootstrap.setup_component(hass, component, config): + + _LOGGER.warn("Could setup event listener for %s", component) + return None + return get_component(component).create_event_listener(schedule, event_data) @@ -57,7 +66,9 @@ def setup(hass, config): for event_data in schedule_data['events']: event_listener = setup_listener(schedule, event_data) - schedule.add_event_listener(event_listener) + + if event_listener: + schedule.add_event_listener(event_listener) schedule.schedule(hass) return True diff --git a/homeassistant/components/sun.py b/homeassistant/components/sun.py index 87832b7cb23..df452db3b78 100644 --- a/homeassistant/components/sun.py +++ b/homeassistant/components/sun.py @@ -225,8 +225,6 @@ class SunsetEventListener(SunEventListener): """ Schedule the event """ next_setting_dt = next_setting(hass) - print("------------", hass, "-------------") - next_time_dt = self.schedule_next_event(hass, next_setting_dt) _LOGGER.info(