Make sure that components isn't loaded multiple times
parent
6f3ef12d31
commit
7e9a254d87
|
@ -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,6 +66,8 @@ def setup(hass, config):
|
|||
|
||||
for event_data in schedule_data['events']:
|
||||
event_listener = setup_listener(schedule, event_data)
|
||||
|
||||
if event_listener:
|
||||
schedule.add_event_listener(event_listener)
|
||||
|
||||
schedule.schedule(hass)
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue