Make sure that components isn't loaded multiple times

pull/25/head
Gustav Ahlberg 2015-02-02 07:30:46 +01:00
parent 6f3ef12d31
commit 7e9a254d87
2 changed files with 16 additions and 7 deletions

View File

@ -18,14 +18,14 @@ entity_ids, and events.
import logging import logging
import json import json
from homeassistant import bootstrap
from homeassistant.loader import get_component from homeassistant.loader import get_component
from homeassistant.const import ATTR_ENTITY_ID from homeassistant.const import ATTR_ENTITY_ID
# The domain of your component. Should be equal to the name of your component # The domain of your component. Should be equal to the name of your component
DOMAIN = 'scheduler' DOMAIN = 'scheduler'
DEPENDENCIES = ['sun'] DEPENDENCIES = []
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -36,13 +36,22 @@ _SCHEDULE_FILE = 'schedule.json'
def setup(hass, config): def setup(hass, config):
""" Create the schedules """ """ Create the schedules """
if DOMAIN in hass.components:
return True
def setup_listener(schedule, event_data): def setup_listener(schedule, event_data):
type = event_data['type'] event_type = event_data['type']
component = type component = type
if type in ('time'): if event_type in ('time'):
component = 'scheduler.{}'.format(type) 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, return get_component(component).create_event_listener(schedule,
event_data) event_data)
@ -57,7 +66,9 @@ def setup(hass, config):
for event_data in schedule_data['events']: for event_data in schedule_data['events']:
event_listener = setup_listener(schedule, event_data) 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) schedule.schedule(hass)
return True return True

View File

@ -225,8 +225,6 @@ class SunsetEventListener(SunEventListener):
""" Schedule the event """ """ Schedule the event """
next_setting_dt = next_setting(hass) next_setting_dt = next_setting(hass)
print("------------", hass, "-------------")
next_time_dt = self.schedule_next_event(hass, next_setting_dt) next_time_dt = self.schedule_next_event(hass, next_setting_dt)
_LOGGER.info( _LOGGER.info(